[Haskell-cafe] Could someone teach me why we use Data.Monoid?

Stephen Tetley stephen.tetley at gmail.com
Fri Nov 13 13:10:06 EST 2009

> Magicloud Magiclouds <magicloud.magiclouds at gmail.com> wrote:

>> That is OK. Since understand the basic concept of monoid (I mean the
>> thing in actual math), the idea here is totally not hard for me. But
>> the sample here does not show why (or how) we use it in programming,
>> right?

Hi Magicloud

Conal Elliott has an interesting paper about designing your programs
in relation to the standard type classes:.


Thinking about the data structures and functions in your program with
regards the standard classes is very useful useful for clarifying your
design. And certainly if you decide your data structure fits the
Monoid interface then you will be presenting it to others who use your
program in the 'standard vocabulary'. But even for Monoid which
seemingly presents a simple interface (mempty, mappend) deciding
whether the _container_ you have is naturally a monoid can be

A personal example, I've been developing a drawing library for a
couple of months and still can't decide whether a bounding box should
be a monoid (mempty, append) or a groupoid (just append) where append
in both cases is union. Even though I haven't resolved this problem,
having the framework of monoid versus groupoid at least gives me the
_terminology_ to consider the problem.

Best wishes


More information about the Haskell-Cafe mailing list