[Haskell] MonadPlus vs. Monoid

Twan van Laarhoven twanvl at gmail.com
Mon Jan 9 13:42:50 EST 2006


I was wondering, in the MonadPlus documentation it says that:
   * mzero is the identity of mplus (and some extra conditions)
   * mplus is an associative operation
While for Monoid we have:
   * mempty is identity of mappend
   * mappend is an associative operation

MonadPlus is of course a 'stronger' assertion. But why is not every 
instance of MonadPlus also an instance of Monoid?

 > instance MonadPlus m => Monoid (m a) where
 >	mempty  = mzero
 >	mappend = mplus

The only type that is an instance of both is [a]. But I see no reason 
why it there should not be a Monoid instance for other MonadPlus types. 
In particular, an instance for Maybe could be useful with a writer monad 
when you are only interested in the first result.

Twan


More information about the Haskell mailing list