Next Atypical Types 52

Type Inference

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."

     sumof :: (Num a) => [a] -> a
     sumof :: (Fractional a) => [a] -> a


Next Copyright © 1999,2008 Mark Dominus