我碰到了一些我在使用Haskell交互提示(ghci)时发现好奇的东西。下ghci中运行下面的代码7.0.4带有数字的类型歧义
[minBound..1]
抛出以下异常:
<interactive>:1:12:
Ambiguous type variable `t0' in the constraints:
(Num t0) arising from the literal `1' at <interactive>:1:12
(Enum t0) arising from the arithmetic sequence `minBound .. 1'
at <interactive>:1:1-13
(Bounded t0) arising from a use of `minBound'
at <interactive>:1:2-9
Probable fix: add a type signature that fixes these type variable(s)
In the expression: 1
In the expression: [minBound .. 1]
In an equation for `it': it = [minBound .. 1]
我知道,写了上为[minBound..1 :: INT]就明确指出“ 1'的意思是Int,但我的问题是,歧义在哪里? “1”可以被解释为诠释,整数,浮动或双,但这些都不只是诠释属于界类。那么还有另外一个可以伪装成字面的类吗?如果不是,那么什么?
很好的答案,谢谢;我正在假设Haskell的类型推断是如何工作的,现在我知道的更好 – Aky 2012-04-23 21:05:14