[Haskell-cafe] Comments from OCaml Hacker Brian Hurt

David Menendez dave at zednenem.com
Fri Jan 16 12:00:40 EST 2009


On Fri, Jan 16, 2009 at 8:39 AM, Duncan Coutts
<duncan.coutts at worc.ox.ac.uk> wrote:

> Ross just updated the documentation for the Monoid module. Here is how
> it reads now:
>
> The module header now reads simply:
>
>        A class for monoids (types with an associative binary operation
>        that has an identity) with various general-purpose instances.
>
> Note, no links to papers.
>
> And the Monoid class has:
>
>        The class of monoids (types with an associative binary operation
>        that has an identity).  The method names refer to the monoid of
>        lists, but there are many other instances.
>
>        Minimal complete definition: 'mempty' and 'mappend'.
>
>        Some types can be viewed as a monoid in more than one way, e.g.
>        both addition and multiplication on numbers. In such cases we
>        often define @newtype at s and make those instances of 'Monoid',
>        e.g. 'Sum' and 'Product'.
>
> If you or anyone else has further concrete suggestions / improvements
> then post them here now! :-)

A reference to the writer monad and to Data.Foldable might be helpful.
So far as I know they are the only uses of the Monoid abstraction in
the standard libraries.

It's probably a good idea to explicitly state the three monoid laws.

It would be nice to explain what operations have been chosen for the
Monoid instances of Prelude data types. (Maybe this belongs in the
Prelude documentation.)

I'd add a reminder that if you're defining a type with a Monoid
instance, your documentation should explain what the instance does.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list