I play with CPS and Control.Monad.Cont and wonder what we get when we notice the monadic structure. For this code:
sumOfSquares'cps :: Cont r Int -> Cont r Int -> Cont r Int sumOfSquares'cps xy = x >>= \x' -> y >>= \y' -> return (x'*x' + y'*y')
It can be easily rewritten as
type Cont' ra = (a -> r) -> r sos'cps :: Cont' r Int -> Cont' r Int -> Cont' r Int sos'cps xy = \k -> x $ \x' -> y $ \y' -> k (x'*x' + y'*y')
Do not get me wrong, but I donβt see the feeling here, except for the ability to use the do and newtype notation. I don't think callCC depends on the monad instance.
I do not have enough imagination to give an example. What do we really get for declaring a Cont r monad?
haskell monads continuation-passing
Sebastian graf
source share