callCC (call-with-current-continuation) calls its argument
function, passing it the current continuation. It provides
an escape continuation mechanism for use with continuation
monads. Escape continuations one allow to abort the current
computation and return a value immediately. They achieve
a similar effect to throwE
and catchE within an
ExceptT monad. The advantage of this
function over calling return is that it makes the continuation
explicit, allowing more flexibility and better control.
The standard idiom used with callCC is to provide a lambda-expression
to name the continuation. Then calling the named continuation anywhere
within its scope will escape from the computation, even if it is many
layers deep within nested computations.