MonadPlus instance for ContT
Edward Kmett
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
> c)
>
> That way both behaviors are easily accessible. Is there any other sensible
> ContT instance for Monoid?
>
Yes.
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
-Edward
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20130624/dc0664d0/attachment.htm>
More information about the Libraries
mailing list