MonadPlus instance for ContT
ekmett at gmail.com
Mon Jun 24 21:07:22 CEST 2013
On Mon, Jun 24, 2013 at 2:53 PM, Dan Burton <danburton.email at gmail.com>wrote:
> I also agree with Henning.
> 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
> That way both behaviors are easily accessible. Is there any other sensible
> ContT instance for Monoid?
The third construction is the 'universal' lifting that works for every
Applicative, which would look like:
instance (Monad m, Monoid a) => Monoid (ContT r m a) where
mempty = return mempty
mappend = liftM2 mappend
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libraries