I don’t actually want it, per se, but I do want to refer to it in an article I’m writing about folds. You’re right: its purpose determines what its implementation should be. In this case, its purpose is to define foldl'
in terms of foldr
. foldl
can be defined in terms of foldr
as
foldl f z t = appEndo (getDual (foldMap (Dual . Endo . flip f) t)) z
and that is, in fact, its implementation in base
. Unless I’m much mistaken, foldl'
can be implemented as
foldl' f z t = appStrictEndo (getDual (foldMap (Dual . StrictEndo . flip f) t)) z
Regarding the other candidates, I’m not sure StrictEndo'
is particularly useful, because runStrictEndo' s x
is just appEndo s $! x
. You can get its behaviour just from Endo
.
By contrast, I don’t think StrictEndo''
does anything at all. The field of a newtype
is already strict. But even if it was a data
type and not a newtype
, you could recover its behaviour from Endo
by using Endo $! f
in place of StrictEndo'' f
. EDIT: This was nonsense.