【发布时间】:2012-04-23 20:08:45
【问题描述】:
我在玩 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' 可以解释为 Int、Integer、Float 或 Double,但除了 >Int 属于 Bounded 类。那么文字 1 是否可以伪装成另一个类?如果不是,那是什么?
【问题讨论】: