
2 Apr
2006
2 Apr
'06
5:53 a.m.
Matthias Fischmann
avg :: (FractionalOrIntegral a) => [a] -> a avg xs = sum (map fromFractionalOrIntegral xs) / (fromIntegral (length xs))
Your condition is probably too strong. For one thing, there is no need to convert every element of the list being summed, just its result. Also, does the final result need to be the same type as the elements? avg :: (Num a, Fractional b) => [a] -> b avg xs = fromRational (sum xs % toInteger (length xs)) Regards, Malcolm