[Haskell-beginners] Newbie question about function type constraints

Imants Cekusins imantc at gmail.com
Thu Sep 22 14:06:52 UTC 2016


Hello,

this works too:

​meanList :: (Fractional a) => [a] -> a
meanList xs = (sumList xs) / (lengthList xs)


sumList :: (Fractional a) => [a] -> a
sumList [] = 0
sumList (x:xs) = x + (sumList xs)


lengthList :: (Fractional a) => [t] -> a
lengthList [] = 0
lengthList (_:xs) = 1 + (lengthList xs)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160922/4c967a0d/attachment.html>


More information about the Beginners mailing list