9 Jan
2006
9 Jan
'06
6:42 p.m.
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