【发布时间】:2016-06-17 09:27:58
【问题描述】:
我正在使用 Haskell 来评估值表的简单限制。我定义了以下函数:
f :: (Integral a) => a -> a
f x = div 1 $ subtract 6 x
在 GHCI 中,我 let leftSide = [5.90, 5.91..5.99] 和 let rightSide = [6.10,6.09..6.01],然后:
GHCI> map f leftSide
这会导致这个错误:
<interactive>:50:5
No instance for (Integral Double) arising from a use of `f'
Possible fix: add an instance declaration for (Integral Double)
In the first argument of `map', namely `f'
In the expression: map f leftSide
In an equation for `it': it = map f leftSide
将我的 f 类型声明更改为 (Integral Double a) => a -> a 会使编译器抱怨“Integral”如何应用于太多类型参数。这是怎么回事?
【问题讨论】:
-
可能是因为
Double不是积分?