
On Thu, Jan 15, 2009 at 11:46 AM, Ross Mellgren
Usually when encountering something like "Monoid" (if I didn't already know it), I'd look it up in the library docs. The problem I've had with this tactic is twofold:
First, the docs for the typeclass usually don't give any practical examples, so sometimes it's hard to be sure that the "append" in "mappend" means what you think it means.
The documentation for Monoid is embarrassingly brief. "The monoid class. A minimal complete definition must supply mempty and mappend, and these should satisfy the monoid laws." It doesn't even list the monoid laws!
Second is that there appears to be no way to document an _instance_. It would be really handy if there were even a single line under "Instances > Monoid ([] a)" that explained how the type class was implemented for the list type. As it is, if you know what a Monoid is already, it's easy to figure out how it would be implemented.
Not necessarily. Any instance of MonadPlus (or Alternative) has at
least two reasonable Monoid instances: (mplus, mzero) and (liftM2
mappend, return mempty). [] uses the first and Maybe uses the second.
I recommend not creating direct instances of Monoid for this reason.
If you want to use Monoid with Int, you have to use Sum Int or Product
Int.
--
Dave Menendez