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

Jonathan Cast jonathanccast at fastmail.fm
Fri Jan 16 13:17:03 EST 2009


On Fri, 2009-01-16 at 17:58 +0000, John Lato wrote:
> > 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.

Agreed.  (Suitably elaborated to show why we didn't just say

    sum $ map countFunction $ getValues

of course!)

Also, the monoid documentation should probably point at
Control.Monad.Writer and Data.Traversable, as well.

> 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.
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think this point is somehow relevant to the discussion at hand...

jcc




More information about the Haskell-Cafe mailing list