Averages/Arithmetic mean: Difference between revisions

Content added Content deleted
Line 333: Line 333:
<lang haskell>mean :: (Fractional a) => [a] -> a
<lang haskell>mean :: (Fractional a) => [a] -> a
mean [] = 0
mean [] = 0
mean xs = sum xs / Data.List.genericLength xs<lang>
mean xs = sum xs / Data.List.genericLength xs</lang>


But some types, e.g. integers, are not Fractional; the following function works for all Real types:
But some types, e.g. integers, are not Fractional; the following function works for all Real types: