我有以下表现:哈斯克尔 - 更多的类型推断问题
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