[Haskell-cafe] commutative monoid?

Evan Laforge qdunkan at gmail.com
Sat Jun 25 23:34:47 CEST 2011


On Sat, Jun 25, 2011 at 2:02 PM, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> Actually, there are (at least) four: there's also the one where
> mappend = liftA2 mappend, i.e. introduce potential failure into a
> monoid operation defined on the values.  I wrote about it here:
>
>    http://byorgey.wordpress.com/2011/04/18/monoids-for-maybe/

Just out of curiosity, what was the problem that wanted this kind of
monoid for the solution?  I always find concrete examples useful in
addition to the abstract explorations and toy examples.

It's Map not Maybe, but in my case, I have "damage", which is
user-modified data that will have to be recomputed.  Given a Map from
IDs to damage ranges, mappending two bits of damage means the ranges
(themselves monoids of course) also have to be mappended.

The case for not lifting is that elsewhere, during said recomputation,
I accumulate some intermediate results for display.  It's actually a
bug if two results share the same ID, but in any case it wouldn't make
sense to merge them, and the value type isn't in monoid.



More information about the Haskell-Cafe mailing list