MonadPlus instance for ContT
Ashley Yakeley
ashley at semantic.org
Sun Jan 11 06:13:28 EST 2009
Wolfgang Jeltsch wrote:
> Hello,
>
> I wonder why there isn’t a MonadPlus instance for ContT. In my opinion, this
> one would be natural:
>
>> instance (MonadPlus monad) => MonadPlus (ContT result monad) where
>>
>> mzero = ContT $ return mzero
>>
>> ContT cont1 `mplus` ContT cont2 = ContT $ liftM2 mplus cont1 cont2
>
> return and liftM2 are the ones of (->) (o -> monad result).
>
> What do you think?
As long as it satisfies the MonadPlus rules.
All of these:
mplus mzero a = a
mplus a mzero = a
mplus (mplus a b) c = mplus a (mplus b c)
mzero >>= k = mzero
and one of these:
mplus a b >>= k = mplus (a >>= k) (b >>= k)
mplus (return a) b = return a
--
Ashley Yakeley
More information about the Libraries
mailing list