我碰到了一些我在使用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