[Haskell-cafe] How to make callCC more dynamic

oleg at okmij.org oleg at okmij.org
Thu Aug 25 07:53:49 CEST 2011

bob zhang wrote:
> I thought the right type for ContT should be
> newtype ContT m a = ContT {runContT :: forall r. (a-> m r) -> m r}
> and
> other control operators
> shift :: Monad m => (forall r . (a-> ContT m r) -> ContT m r) -> ContT m a
> reset :: Monad m => ContT m a -> ContT m a
> callCC :: ((a-> (forall r . ContT m r)) -> ContT m a) -> ContT m a
> unfortunately, I can not make callCC type check, and don't know how to
> do it.

Precisely that problem was discussed in  

Your ContT is CPS1 in the above article. The article shows why you
cannot write callCC with the above type of ContT. The article talks
about other types. BTW, if you faithfully defined the monad for
undelimited control than shift/reset cannot be expressed. Undelimited
continuations are strictly less expressible than delimited ones. The
above page gives the pointers to the papers with the proof.

More information about the Haskell-Cafe mailing list