Averages/Pythagorean means: Difference between revisions
m
→Three applicatively defined functions: liftA2 -> ((.) ... <*>)
(→Haskell Three applicatively defined functions: Replaced liftM2 with liftA2) |
m (→Three applicatively defined functions: liftA2 -> ((.) ... <*>)) |
||
Line 1,259:
====Three applicatively defined functions====
These three functions (each combining the length of a list with some kind of fold over the elements of that same list), all share the same
<lang haskell>import
-- ARITHMETIC, GEOMETRIC AND HARMONIC MEANS ---------------
arithmetic, geometric, harmonic :: [Double] -> Double
arithmetic =
geometric =
harmonic =
-- TEST ---------------------------------------------------
Line 1,283 ⟶ 1,281:
, mappend "\n A >= G >= H is " $ --
(show . and) $ zipWith (>=) xs (tail xs)
]</lang>
{{Out}}
<pre>("Arithmetic",5.5)("Geometric",4.528728688116765)("Harmonic",3.414171521474055)
|