|sumof ::||(Num a) => [a] -> a|
|h ::||(Num a) => a|
|t ::||(Num a) => [a]|
"So the return value is really (Num a) => a."
sumof  = 0 sumof (h:t) = h + sumof t
"That fits with the other return value of 0."
"And everything else checks out okay."
If you ask, it will say that the type is:
sumof :: (Num a) => [a] -> a
If we had put 0.0 instead of 0, it would have deduced:
sumof :: (Fractional a) => [a] -> a
(Fractional is a subclass of Num)
Among other things, it supports division
If we had put "Fred" we would have gotten a type error
Because String is not an instance of Num
|Next||Copyright © 1999,2008 Mark Dominus|