MonadPlus instance for ContT

Henning Thielemann lemming at
Mon Jun 24 19:53:52 CEST 2013

On Mon, 24 Jun 2013, John Wiegley wrote:

>>>>>> Ross Paterson <R.Paterson at> writes:
>> Alistair Lynn has proposed the following instance:
>>   instance (Monoid r, Monad m) => MonadPlus (ContT r m) where
>>     mzero = ContT $ const $ return mempty
>>     m `mplus` n = ContT $ \ c -> liftM2 mappend (runContT m c) (runContT n c)
>> but this would also be possible:
>>   instance (MonadPlus m) => MonadPlus (ContT r m) where
>>     mzero = ContT $ const mzero
>>     m `mplus` n = ContT $ \ c -> runContT m c `mplus` runContT n c
>> Is one of them better?
> I would think that allowing ContT to transform any Monad over any Monoid has
> more utility than only transforming another MonadPlus.  But I have no real
> world data to back this up, just a hunch.

I guess that if someone has a MonadPlus monad, then he wants to continue 
to use it when the monad stack grows by a ContT. This would give 
preference to the second instance.

More information about the Libraries mailing list