[Haskell-cafe] Re: Comments from OCaml Hacker Brian Hurt

John Lato jwlato at gmail.com
Fri Jan 16 12:58:27 EST 2009

> On Fri, 16 Jan 2009, Duncan Coutts wrote:
>> If you or anyone else has further concrete suggestions / improvements
>> then post them here now! :-)

Show various examples of how monoids apply to programming
concepts/problems, e.g. monoids to combine configuration
parameters/flags, monoids in writers, etc.  Show how using the
abstract monoid class is an advantage over a less abstract class/type
with concrete examples.

> Jonathan Cast wrote:
> To accumulate a running count, maybe?  A fairly common pattern for
counting in imperative languages is

> int i = 0;
> while (<get a value>) i+= <count of something in value>

> Using the writer monad, this turns into
> execWriter $ mapM_ (write . countFunction) $ getValues

This should be in the documentation for Writer.  It shows how a writer
can usefully and simply perform a specific function, and that function
is different from what most users would consider using a Writer for.
Hence, it's a specific example of both the advantages that generality
provides* and a programming use for a monoid.

John Lato

*) just being more general isn't always an advantage.  As abstractions
progress, iIt becomes increasingly difficult to apply abstract
concepts to the task at hand.  This essay,
http://discuss.joelonsoftware.com/default.asp?joel.3.219431.12, has a
pretty good description of taking this too far.

More information about the Haskell-Cafe mailing list