[Haskell-cafe] Another monad question...
Stefan O'Rear
stefanor at cox.net
Sun Jul 15 00:23:12 EDT 2007
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 :(
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070714/8ed54b41/attachment.bin
More information about the Haskell-Cafe
mailing list