Containers and folds

wren ng thornton wren at
Sat Sep 25 18:19:09 EDT 2010

On 9/24/10 1:45 PM, Thomas Schilling wrote:
> Regarding the questions:  I prefer the foldr/l names, because
> otherwise I may need to look up the documentation to figure out which
> fold it is. It's much better to use the standard naming convention
> from lists.  As an example, there is foldM which is actually a left
> fold.  Data.Foldable fixes this and only uses the generic name 'fold'
> for the Monoid case where order does indeed not matter due to
> associativity of mappend.

I agree with both parts of this. That is, foldr/l are the best names for 
when the order is specified. However, sometimes we do have an 
associative operator and don't care about the order. In these latter 
cases I think it's best to offer a "fold" which doesn't specify order in 
order to prevent client code from over-specifying what they mean.

Also, having an order-independent fold allows the library to choose 
whatever kind of fold would be most efficient (possibly changing it over 
time), and allows for things like a parallel implementation for 
overcoming the "fold considered harmful"[1] problem.


Live well,

More information about the Libraries mailing list