User Tools

Site Tools


Continuation passing style

More commonly, functions return a value directly this is called direct style.

λ continuation_passing_style-direct

Continuation passing style (CPS) is a style of programming where the control is passed directly as a continuation function. A function written in CPS takes an extra argument which is an explicit continuation, a function which takes the return result as a single argument.

λ continuation_passing_style-continuation

This makes some things more explicit, such as returning values. Which allows for more control over how these aspects of programming function. A simple example of control over returning values is delaying the time at which the value is returned.

λ continuation_passing_style-delayed

Continuations are not just limited to a single return continuation. The Javascript interpreter that runs the code in these examples takes 6 different continuations. These handle control flow for things like breaking from for loops and exceptions.

continuation_passing_style.txt · Last modified: 2015/02/02 08:28 (external edit)