[Haskell-cafe] Map Monoid instance (was commutative monoid?)

Jens Blanck jens.blanck at gmail.com
Sat Jun 25 18:00:57 CEST 2011

I don't think the original question really is about commutativity, but
rather the choice of Monoid instance.

Not being especially mathematically inclined, every once and a while I
> get a little panicked when I notice that, e.g. Data.Map mappend is a
> plain left-biased union, and doesn't actually mappend the values of
> the map.

As noted in the reply

> > So there's a range of possible Monoid instances for each type,
> More for some types than for others. For Maybe there are three:
>  * always take the first/left value;
>  * always take the last/right value;
>  * or, use a semigroup operation defined on the values.
> The first two options are provided by the First and Last newtypes, and the
> third option is provided by the instance for Maybe itself (except that it
> spuriously requires a Monoid instance instead of just a semigroup).
But why does the Map instance of Monoid _not_ mimic the one chosen for
Maybe. I claim this causes unnecessary surprises for users (and lifting the
Monoid instance seems more useful, but that is harder to substantiate).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110625/15c22109/attachment.htm>

More information about the Haskell-Cafe mailing list