【发布时间】:2014-11-14 07:23:25
【问题描述】:
在 GHCi 中,如果我这样定义两个函数:
> let succ = (+ 1)
> let pred = (- 1)
然后调用它们,像这样:
> succ 5
> pred 5
为什么一个 (succ) 运行正常,而另一个失败并出现以下错误?
<interactive>:3:1:
Could not deduce (Num (a0 -> t))
arising from the ambiguity check for ‘it’
from the context (Num (a -> t), Num a)
bound by the inferred type for ‘it’: (Num (a -> t), Num a) => t
at <interactive>:3:1-6
The type variable ‘a0’ is ambiguous
When checking that ‘it’
has the inferred type ‘forall a t. (Num (a -> t), Num a) => t’
Probable cause: the inferred type is ambiguous
是什么导致类型推断在一个函数而不是另一个函数中失败?
【问题讨论】:
标签: haskell