I have a simple function defined below:
allZero :: Num a => [a]-> Bool
allZero [] = False
allZero xs = and (map (== 0) xs)
This returns an error message upon loading:
Could not deduce (Num a) arising from the literal `0'
What is the problem with this function? How do I oveload the number 0 to be of any numeric type a?
Num
in the type-class hierarchy changed (a while ago), it may be worth specifying which version of GHC you're using. – jub0bsallZero []
to return true. You can also useall (==0) xs
instead ofand (map (==0) xs)
. – chi