Adding partial foldl1' to Foldable?
Viktor Dukhovni
ietf-dane at dukhovni.org
Sun Dec 20 22:15:57 UTC 2020
Given that Foldable currently has:
- foldr and foldr'
- foldl and foldl'
- foldMap and foldMap'
and also has only:
- foldr1
- foldl1
it seems natural to ask whether there it should also have a strict
variant of at least foldl1, since the non-strict variant has rather
limited applicability, and users would/should in most cases want/use
the strict `foldl1'` instead.
--
Viktor.
P.S. I just joined the list today, but noticed that coincidentally, there's
already a recent dicussion of Foldable1, which rather overlaps with this
question, and perhaps the partial `foldr1` and `foldl1` should be seen
as deprecated, once a suitable class of non-empty containers provides
total variants. But perhaps on the other hand, given that the partial
functions already exist, perhaps adding the strict companions is
warranted?
I am asking because I am writing some expository prose for
Data.Foldable, to go at the bottom of the document, structurally along
the lines of what I contributed for Data.Traversable, but with a fairly
different focus. The goal is draw careful distinctions between
strict recursive and lazy corecursive reductions, explaining their
proper usage and typical implementations. The "missing" `foldl1'`
was something I ran into while working on part of the writeup.
More information about the Libraries
mailing list