
On 9/4/07, ok
I've been thinking about making a data type an instance of MonadPlus. From the Haddock documentation at haskell.org, I see that any such instance should satisfy
mzero `mplus` x = x x `mplus` mzero = x mzero >>= f = mzero v >> mzero = mzero
but is that all there is to it? Are there no other requirements for MonadPlus to make sense?
Also, mplus has to be associative. I.e. (a `mplus` b) `mplus` c == a `mplus` (b `mplus` c)
I also wondered why, once MonadPlus was added to the language, the definition of ++ wasn't changed to (++) = MonadPlus (with the MonadPlus instance for [] defined directly).
You mean (++) = mplus. I've wondered that too. Similarly, one should define map = fmap. And a lot of standard list functions can be generalized to MonadPlus, for example you can define filter :: (MonadPlus m) => (a -> Bool) -> m a -> m a (This is not the same as filterM.)