[Haskell-cafe] callCC inside expression

Mikael Brockman mbrock at goula.sh
Fri Jul 25 10:04:48 UTC 2014


martin <martin.drautzburg at web.de> writes:

> Hello all
>
> I recently saw a video on call/cc in Scheme, where call/cc was used
> inside an expression and call/cc faithfully figured out the rest of
> the computation.
>
> I tried the same in haskell, but was bitten badly. Then I looked at
> the type signature and learned that call/cc only works inside a
> continuation monad (if I am not mistaken).
>
> Is this correct and why is that so? Are scheme's call/cc and haskell's
> callCC semantically different?

The ContT monad transformer provides "delimited continuations," aka
"composable continuations" or "partial continuations."  These are much
easier to use and reason about than global continuations.  A
continuation reified by callCC can be reused as a regular monadic
action; it won't disrupt the entire program's evaluation.

There's an Oleg article [1] that argues against Scheme's call/cc as a
"bad abstraction" for numerous reasons.  I believe it's good Scheme
coding practice to avoid this operator in favor of some construction for
delimited continuations, such as shift & reset, though standard Scheme
only specifies call/cc.

Oleg says:

| Undelimited continuations by themselves seem to have no practical use:
| at least noone has shown me a practical application of just call/cc,
| which I have been asking for a long time. To my knowledge, in all
| practical programs call/cc emulates, to the extent possible, some sort
| of a delimited control operation, often as simple as exceptions or
| generators.

Scheme seems to retain call/cc mostly by inertia.

[1]: http://okmij.org/ftp/continuations/against-callcc.html



More information about the Haskell-Cafe mailing list