Proposal: Add a few extra members to Foldable and Traversable classes

David Feuer david.feuer at gmail.com
Thu Sep 18 21:37:33 UTC 2014


To go along with Herbert Valerio Riedel's moving functions from Foldable
and Traversable to Prelude, I realized that `null` and `size` make sense
for all Foldables; Reid W. Barton noted that these can have optimized
implementations for many containers. He also noted that scanl1 and scanr1
make sense for general Traversables. I therefore propose:

Add `null` and `size` to the Foldable class. Default implementations:

null = foldr (\_ _ -> False) True

size = foldl' (\acc _ -> acc+1) 0

Add `scanl1` and `scanr1` to the Traversable class. Default implementations
are a little less simple.

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140918/8bd3c2d0/attachment.html>


More information about the Libraries mailing list