15-150: Principles of Functional Programming

Lecture 12: Programming with continuations

Continuations act as "functional accumulators". The basic idea is to implement a function f by defining a function f' that takes an additional argument, called the continuation. This continuation is a function; it encapsulates the computation that should be done on the result of f. In the base case, instead of returning a result, one calls the continuation. In the recursive case, one augments the given continuation with whatever computation should be done on the result. In exceptional cases, we may discard (or duplicate) the continuation to circumvent the normal control flow.

Key Concepts

Sample Code

Some Notes on Continuations

Lecture Slides

Slides from lecture