我已经做了类型的类的实例时有问题,并提出列表类型的类的实例,但我得到它,我不明白使得列表中的类型类
class MyType a where
listsum:: a->a->Double
instance (Num a)=>MyType [a] where
listsum x y = sum $ zipWith (-) x y
listsum返回错误单值但这是错误,我得到:
Could not deduce (a ~ Double)
from the context (Num a)
bound by the instance declaration at b2.hs:4:10-28
`a' is a rigid type variable bound by
the instance declaration at b2.hs:4:10
In the expression: sum $ zipWith (-) x y
In an equation for `listsum': listsum x y = sum $ zipWith (-) x y
In the instance declaration for `MyType [a]'
Failed, modules loaded: none.
如何解决这个问题?
@chi - 是的,这就是我得到的懒惰心理typechecking,现在修复... – sclv