The control operator, traditionally the counterpart of prompt. It does
not delimit the reified subcontinuation, so control effects therein can
escape. The corresponding prompt is performed equally well by reset above.

Examples

This module provides many different control operators, so hopefully the
examples herein can help in selecting the right ones. The most raw are the
four contained in the MonadDelimitedCont type class. The first, of course,
is newPrompt, which should be straight forward enough. Next comes
pushPrompt, which is the basic operation that delimits a computation.
In the absense of other control operators, it's simply a no-op, so

pushPrompt p (return v) == return v

withSubCont is the primitive that allows the capture of sub-continuations.
Unlike callCC, withSubCont aborts the delimited continuation it captures,
so:

will yield the answer [1, 2]. However, Capturing a sub-continuation and
immediately pusshing it is not a no-op, because the sub-continuation
does not contain the delimiting prompt (and, of course, pushSubCont does
not re-instate it, as it doesn't know what prompt was originally used).
Thus, capturing and pushing a sub-continuation results in the net loss of
one delimiter, and said delimiter will need to be re-pushed to negate that
effect, if desired.

Out of these four primitive operators have been built various functional
abstractions that incorporate one or more operations. On the delimiting
side is reset, which combines both prompt creation and delimiting. In
some papers on the subject (such as Shift to Control), each capture
operator would be paired with a corresponding delimiter operator (and
indeed, a separate CPS transform). However, since prompts are explicitly
passed in this implementation, a single delimiter suffices for supporting
all capture operators (although pushPrompt will need to be used if one
wishes to explicitly push a prompt more than once).

The simplest control flow operator is abort, which, as its name suggests,
simply aborts a given sub-continuation. For instance, the second example
above can be written:

pushPrompt p ((1:) `liftM` (2:) `liftM` abort p (return []))

The rest of the functions reify the sub-continuation into a function,
so that it can be used. The shift/control operators all have similar
effects in this regard, but differ as to where they delimit various
parts of the resulting computation. Some names may help a bit for the
following explanation, so consider:

shift p (\f -> e)

p is, obviously, the prompt; f is the reified continuation, and e
is the computation that will be run in the aborted context. With these
names in mind, the control operators work as follows:

shift delimits both e and every invocation of f. So, effectively,
when using shift, control effects can never escape a delimiter, and
computations of the form:

reset (\p -> <computations with shift p>)

look pure from the outside.

control delimits e, but not the sub-continuation in f. Thus, if
the sub-continuation contains other control invocations, the effects
may escape an enclosing delimiter. So, for example:

control0 delimits neither e nor f, and is, in effect, the reified
analogue to using withSubCont and pushSubCont directly.

For a more complete and in-depth discussion of these four control operators,
see Shift to Control, by Chung-chieh Shan.

A small example program follows. It uses delimited continuations to reify a
monadic loop into an iterator object. Saving references to old iterators
allows one to effecively store references to various points in the traversal.
Effectively, this is a simple, restricted case of a generalized zipper.