MonadPlus instance for ContT

Ross Paterson R.Paterson at city.ac.uk
Mon Jun 24 22:03:43 CEST 2013


On Mon, Jun 24, 2013 at 11:53:06AM -0700, Dan Burton wrote:
> If anything, the 1st instance could be a ContT instance for Monoid.
> 
> instance (Monoid r, Monad m) => Monoid (ContT r m a) where
>   mempty = ContT $ const $ return mempty
>   m `mappend` n = ContT $ \ c -> liftM2 mappend (runContT m c) (runContT n c)
> 
> That way both behaviors are easily accessible.

There's a school of thought that holds that the Monoid and Alternative
(and therefore MonadPlus) instances on any functor should agree:

http://thread.gmane.org/gmane.comp.lang.haskell.cafe/94642



More information about the Libraries mailing list