
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? Best wishes, Wolfgang

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

Am Sonntag, 11. Januar 2009 12:13 schrieben Sie:
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
Should all be satisfied.
and one of these:
mplus a b >>= k = mplus (a >>= k) (b >>= k)
Should be satisfied.
mplus (return a) b = return a
Obviously not satisfied in general. What has to be done to get such an instance into the libs? Best wishes, Wolfgang
participants (2)
-
Ashley Yakeley
-
Wolfgang Jeltsch