Proposal: Add First and Last wrappers around Maybe to Data.Monoid

Jeffrey Yasskin jyasskin at
Mon Mar 5 17:11:58 EST 2007

On 3/4/07, David Menendez <zednenem at> wrote:
> Jeffrey Yasskin writes:
> > I've created to
> > suggest adding two Monoid instances around Maybe that, instead of
> > accumulating things like most monoids, just pick the first or last
> > piece of data they see.
> Rather than have two wrappers, I say make the a Monoid instance for
> Maybe using a left-biased choice (like the MonadPlus instance).
> Then we would get right-biased choice for free with the Dual wrapper.

That's a reasonable idea, but I chose against it in the proposal
because it arbitrarily picks one of the two sensible monoids for
Maybe, which I'm worried will confuse users, especially since Haddock
doesn't currently provide documentation for instances. Also, (getDual
. foldMap (Dual . f)) is less readable than (getLast . foldMap (Last .
f)). On the other hand, maybe the usual case is to just want any
result, rather than specifically the left-most or right-most one, in
which case providing the instance for Maybe directly saves typing.

Thanks for the comment,

More information about the Libraries mailing list