The binding strategy for ContTignores the internal monad; in fact, the code is the same as for Cont.
Following an analogy with other Monad Transformers, I would implement it as follows:
return x = ContT ($ (return x))
(>>=) x f = ContT (\k -> runContT x ((=<<) (\a -> runContT (f a) k)))
Then, for example, this expression:
do
x1 <- ContT (\k -> k [1, 2])
x2 <- ContT (\k -> k [10, 20])
return ((+) x1 x2)
The result will be [11, 21, 12, 22]
My question is, what is the reason for this design decision? Why it was implemented in a way that is very different from other Monad Transformers, note that the functor instance:
fmap f m = ContT $ \c -> runContT m (c . f)
but not:
fmap f m = ContT $ runCont $ (fmap . fmap) f (Cont (runContT m))
, Monad Transformers, , , , , , , , , -. , , ?
IdentityT , , Cont , Identity, ContT IdentityT?