我有以下表現:哈斯克爾 - 更多的類型推斷問題
getCount :: (Num a) => a -> [a]
getCount int = foldl
processOneCount
[0,0,0,0,0,0,0,0,0,0]
(map (singleDigitCount) (map (digitToInt) (show int)))
,我也得到了以下錯誤:
Couldn't match expected type `a' against inferred type `Int'
`a' is a rigid type variable bound by
the type signature for `getCount'
at C:\Users\RCIX\Desktop\Haskell Code\test.hs:23:17
Expected type: [a]
Inferred type: [Int]
In the expression:
foldl
processOneCount
[0, 0, 0, 0, ....]
(map (singleDigitCount) (map (digitToInt) (show int)))
In the definition of `getCount':
getCount int
= foldl
processOneCount
[0, 0, 0, ....]
(map (singleDigitCount) (map (digitToInt) (show int)))
然而,當我做了:t [0,0,0,0,0,0,0,0,0,0]
我回來[0,0,0,0,0,0,0,0,0,0] :: (Num t) => [t]
。那麼爲什麼我不能在第一個表達式中使用它?
哦。我應該堅持一個int類型,還是有辦法強制輸出成Num? – RCIX 2010-01-14 22:11:43
'fromIntegral ::(Integral a,Num b)=> a - > b' – ephemient 2010-01-14 22:12:49
感謝您的幫助:) – RCIX 2010-01-14 22:15:41