The literature on continuations and delimited control is vast. This blog post is intended as an opinionated starting point, to introduce the key ideas and issues at a high level and provide pointers to the relevant papers.
Programming with shift and reset
A good starting point is to get some intuition writing programs which use shift and reset, in a sense the most well-behaved of the family of operators. Kenichi Asai's tutorial has many examples.
The easiest language to try them in today is Racket, which has the most complete library of operators.
(example)
A close second is OCaml, using delimcc_of_fxhandler. Two caveats are that 1. a library is needed for multishot continuations, and 2. the type system does not help. An alternative is this port of Oleg Kiselyov's Genuine Shift/Reset, which provides a typed monadic API.
(example)
Use cases
- Nondeterminism
- Probabilistic programming
- Automatic differentiation
There is significant overlap in use cases with effect handlers.
Semantics of shift and reset
Answer-type modification
Other operators in the family
Distinguishing shift and control
Distinguishing shift and shift0
Distinguishing control and control0
In what sense is shift static, and control dynamic?
importantly, not the same as lexical scope and dynamic scope.
Relation to algebraic effects
shift0 corresponds to deep handlers, and control0 corresponds to shallow.