On Fri, Jul 1, 2011 at 12:21 PM, Eugene Kirpichov <ekirpic...@gmail.com> wrote: > I meant the average of the whole list - given a sumS and lengthS ("S" > for "Stream"), write meanS as something like liftS2 (/) sumS lengthS. > > Or is that possible with lazy lists too? > Sure you can. Sum, length and mean could be calculated as left fold. If you need to calculate more that one statistic at time you can combine accumulators
> sum = foldl (+) 0 > length = foldl (\n _ -> n+1) 0 > data Mean Double Int > mean = foldl (\(Mean m n) x -> Mean (m + (x - m) / fromIntegral (n+1)) (n+1)) > (Mean 0 0) AFAIU iteratees basically use same technique. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe