Cumulative standard deviation: Difference between revisions
→{{header|Haskell}}: Switched foldl version to a more natural expression in terms of mapAccumL
m (→{{header|AppleScript}}: Updated primitives) |
(→{{header|Haskell}}: Switched foldl version to a more natural expression in terms of mapAccumL) |
||
Line 1,828:
Or, as a map-accumulation over an indexed list
<lang Haskell>
-------------- CUMULATIVE STANDARD DEVIATION -------------
cumulativeStdDevns :: [Float] -> [Float]
cumulativeStdDevns xs = snd $ mapAccumL go (0, 0) $ zip [1 ..] xs
where
in ((_s, _q), sqrt ((_q / _i) - ((_s / _i) ^ 2)))
--------------------------- TEST -------------------------
main :: IO ()
main = mapM_ print
{{Out}}
<pre>0.0
|