Containers and folds

Ian Lynagh igloo at
Sat Sep 25 08:41:39 EDT 2010

On Fri, Sep 24, 2010 at 07:09:56PM +0200, Milan Straka wrote:
> I therefore propose to:
> a) add foldrWithKey and foldlWithKey to IntMap, make foldWithKey
>    deprecated and synonymous for foldrWithKey.


Why not also add foldl and foldr to Map and IntMap, and deprecate fold?

> b) add foldl and foldr to Set and IntSet, make fold deprecated
>    and synonymous to foldr.


> c) add strict variants of left and right folds, namely
>   Data.Map, Data.IntMap: foldlWithKey' foldrWithKey'


Again, why not foldl' and foldr' too?

>   Data.Set, Date.IntSet: foldl', foldr'


> Some issues:
> - should we really rename fold -> foldr?


> - should we really deprecate fold and foldWithKey?


> It could break a lot of code.

If that is a big worry, then it can be documented as deprecated with
7.2, have a deprecated pragmas with 7.4, and be removed with 7.6.

That way, packages can remain -Wall clean while supporting a pair of GHC

> - adding foldl, foldr, foldl' and foldr' to Set and IntSet is going to
>   cause a lot of trouble because of shadowing.

You mean name collisions with Prelude/Data.List? That's fine for these
libraries; they already define things like map.


More information about the Libraries mailing list