[Haskell-cafe] Finding the average in constant space

Chris Wong chrisyco+haskell-cafe at gmail.com
Sun May 27 10:04:46 CEST 2012


Hello all

I just came up with a way of executing multiple folds in a single
pass. In short, we can write code like this:

   average = foldLeft $ (/) <$> sumF <*> lengthF

and it will only traverse the input list once.

The code is at: https://gist.github.com/2802644

My question is: has anyone done this already? If not, I might release
this on Hackage -- it seems quite useful.

Chris



More information about the Haskell-Cafe mailing list