Containers and folds

Milan Straka fox at
Fri Sep 24 13:09:56 EDT 2010


the Set, and IntSet have one 'fold' that does not specify order of
folding (but in fact are right folds).

Map and IntMap have 'fold' and 'foldWithKey' which is a right fold
(and documented as such).

Recently foldrWithKey and foldlWithKey was added to Data.Map
(foldWithKey is deprecated and a synonymous for foldrWithKey).

There are two thinks to sort out: a) add left/right folds, b) add strict

I therefore propose to:
a) add foldrWithKey and foldlWithKey to IntMap, make foldWithKey
   deprecated and synonymous for foldrWithKey.
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'
  Data.Set, Date.IntSet: foldl', foldr'

Some issues:
- should we really rename fold -> foldr? Maybe we could cla
  that fold and foldWithKey are right folds and add only
  foldl and foldlWithKey.
- should we really deprecate fold and foldWithKey? It could break
  a lot of code.
- adding foldl, foldr, foldl' and foldr' to Set and IntSet is going to
  cause a lot of trouble because of shadowing. Maybe some better name?
  On the other hand, these are the "right" names.

Discussion period: three weeks (because of ICFP).
Discussion ends: 15th Oct.


More information about the Libraries mailing list