[Haskell-cafe] Another monad question...

Jonathan Cast jcast at ou.edu
Sun Jul 15 01:00:58 EDT 2007


On Saturday 14 July 2007, Stefan O'Rear wrote:
> On Sun, Jul 15, 2007 at 12:03:06AM -0400, David LaPalomento wrote:
> > On 7/14/07, Stefan O'Rear <stefanor at cox.net> wrote:
> >> Your base case is subtly wrong - it should be return [], not mzero.
> >> Mzero always fails - mzero `mplus` x = x, by one of the MonadPlus laws.
> >
> > Ah!  So here's another quick question: if mzero is the identity element,
> > why isn't it part of the Monad class?  Correct me if I'm wrong but aren't
> > Monads (in the mathematical sense) required an identity element by
> > definition?
>
> You're probably confusing Monads with Monoids.
>
> Monoid:
>   * Concept from abstract algebra
>   * A set Ty, a distinguished element mempty :: Ty, and a binary operator
>     mappend :: Ty -> Ty -> Ty
>   * mempty `mappend` x = x
>   * x `mappend` mempty = x
>   * a `mappend` (b `mappend` c) = (a `mappend` b) `mappend` c
>
> Monad:
>   * Concept from category theory
>   * A category C (assumed to be Haskell objects in the type class)
>   * A functor F :: C -> C
>   * Two natural transformations η :: F^0 -> F^1, μ :: F^2 -> F^1
>   * the monad laws
>
> MonadPlus:
>   * Monads that are also monoids
>   * mappend, mempty named mplus, mzero to avoid conflicts
>   * (OK it was the other way around, monadplus came first)
>
> I've heard that Monads are in some way like Monoids, hence the name.
> But I don't understand the explanation yet myself :(

A regular algebra monoid (in the context of category theory) is a triple (M, 
e : 1 -> M, * : M * M -> M), where 1 is an arbitrary one-element set and M * 
M is the regular cartesian product, satisfying certain laws.  Categorical 
monoids generalize this in two ways: first, the category chosen doesn't have 
to be Set, and second the product operator doesn't have to be the cartesian 
product, but can be an arbitrary bifunctor, as long as that bifunctor is 
itself a monoid.  So, if C is a category, the functor category C^C is a 
monoidal category with the identity functor in for the terminal object 
operator and composition in for the product, and a monoid in that category is 
a monad in C.

Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs


More information about the Haskell-Cafe mailing list