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

Edward Kmett ekmett at gmail.com
Fri Nov 13 13:43:35 EST 2009


On Fri, Nov 13, 2009 at 1:10 PM, Stephen Tetley <stephen.tetley at gmail.com>wrote:

> > 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:.
>
> http://conal.net/papers/type-class-morphisms/
>
> 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
> difficult.
>
> 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.
>


Watch out, in more common parlance, having just an binary operation is a
magma, while having a category with full inverses yields a groupoid. I
haven't seen many people use the older groupoid term for magmas, if only
because they started to have naming conflicts with the category theory
people, and Bourbaki's 'magma' was available and unambiguous. =)

And of course magma is not to be confused with the notion of a semigroup,
which is a binary associative operation, and is therefore much more similar
to a monoid in that all it lacks is a unit.

-Edward Kmett


>
> Best wishes
>
> Stephen
>  _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091113/35a63908/attachment.html


More information about the Haskell-Cafe mailing list