| Next | Atypical Types | 51 |
| sumof :: | [a] -> b |
| h :: | a |
| t :: | [a] |
"h must have type a and t must have type [a]."
sumof [] = 0
sumof (h:t) = h + sumof t
"We're adding h to the return value of sumof."
"So the return value must be a also."
"And + is only defined for instances of Num, so a is such an instance
"So the return value is really of type (Num a) => a."
sumof :: (Num a) => [a] -> a
| Next | ![]() |
Copyright © 1999,2008 Mark Dominus |