Re: Comments from OCaml Hacker Brian Hurt

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.

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
participants (2)
-
John Lato
-
Jonathan Cast