Anonymous user
Averages/Arithmetic mean: Difference between revisions
→{{header|Haskell}}
(added php) |
|||
Line 175:
=={{header|Haskell}}==
This function works if the element type is an instance of Fractional:
mean :: (Fractional a) => [a] -> a
mean [] = 0
mean xs = sum xs / Data.List.genericLength xs
But some types, e.g. integers, are not Fractional; the following function works for all Real types:
meanReals :: (Real a, Fractional b) => [a] -> b
meanReals = mean . map realToFrac
=={{header|IDL}}==
|