Haskell CS 421 LogoCS 421 — Programming Languages

Continuation Passing Style


You have seen, especially in the Higher Order Functions lecture, how we can use functions to generalize an operation. Continuations are another example of this. Many languages have a return keyword to tell the program to return from a function call with a certain result. What if you could replace that with a parameter of your own choosing? The result is called a continuation, and they have enormous power over the execution flow of a program.

These may well seem abstract to you, but you will recognize them if you ever program in languages like Javascript, where they are usually called “callbacks”.