[Haskell-cafe] Re: what is inverse of mzero and return?
Jorge Adriano Aires
jadrian at mat.uc.pt
Sun Jan 23 09:58:56 EST 2005
> >>What would happen if this was the definition?
> >>instance MonadPlus  where
> >> mzero = 
> >> mplus a b
> >> | a ==  = b
> >> | otherwise = a
> Isn't the above a monoid as well?
> Is there only on correct definition of a monad/monoid on lists - or does
> anything that satisfies the monad laws count? I got the impression you
> could define anthing you liked for mzero and mplus - providing the laws
> are upheld?
I'm not arguing that definition would be "wrong". It is a monoid. This is the
instance for ():
instance MonadPlus() where
mzero = ()
mplus a b = ()
And this would be "correct" too:
instance MonadPlus Maybe where
mzero = Nothing
mplus a b = Nothing
instance MonadPlus  where
mzero = 
mplus a b = 
Which are not really useful. I'm claiming that the fact that Maybe is a
trivial Monoid doesn't mean we should "dumb" down other instances, like the
one on lists. The usual definition of Monoid on lists is  as identity and
++ as the monoid operation. That is how it's defined in class monoid, and I
expect this relation to hold:
instance MonadPlus m => Monoid (m a) where
mempty = mzero
mappend = mplus
> >Then, I'd say you're not thinking of monadic sums, but of catching errors,
> > and the appropriate place for that is the class MonadError.
> I am thinking about how some monads are summed - like Maybe and
> the Parser monad.
But, this is not how monadic parsers are summed. Just look into the instace of
MonadError for Text.ParserCombinators.ReadP.P. Again it would be the case for
parsers that would return just one possible parsing, but not for parsers that
More information about the Haskell-Cafe