小编eDr*_*n55的帖子

Haskell列表理解(列表元素的打印sqrt)

我有GHCi,版本7.8.3.我想计算sqrt项的总和,它可以被10整除.

如果我写[ x | x <- [10..100], x `mod` 10 == 0]sum [sqrt x | x <- [10..100]]正确.

但如果我sum [ sqrt x | x <- [10..100], x `mod` 10 == 0]在显示错误时写入:

'<interactive>:39:1:
    No instance for (Show t0) arising from a use of ‘print’
    The type variable ‘t0’ is ambiguous
    Note: there are several potential instances:
      instance Show Double -- Defined in ‘GHC.Float’
      instance Show Float -- Defined in ‘GHC.Float’
      instance (Integral a, Show a) …
Run Code Online (Sandbox Code Playgroud)

haskell list-comprehension list

4
推荐指数
1
解决办法
343
查看次数

标签 统计

haskell ×1

list ×1

list-comprehension ×1