Home

continuationstyle

Continuationstyle, sometimes written as continuation style, is a term used in programming to describe a style of constructing computations in which the future of the computation—the continuation—is made explicit. In this approach, functions do not return values in the usual sense. Instead, they take an extra argument, the continuation, which represents the rest of the computation and is invoked with the function’s result. This makes control flow a first-class entity that can be created, stored, passed around, and composed.

The concept is most closely associated with continuation-passing style (CPS). CPS is a formalization in which

Example (very small): in direct style, a function f(x) might return x + 1. In CPS, f(x, k)

Applications and considerations: continuationstyle is a core technique in compiler design, program analysis, and language design.

Related concepts include continuation-passing style, call-with-current-continuation (call/cc), and defunctionalization.

every
function
takes
a
continuation
as
an
argument
and
ends
by
calling
that
continuation
with
the
result.
This
contrasts
with
direct
style,
where
functions
return
and
the
call
stack
determines
the
remaining
steps.
CPS
enables
precise
modeling
of
control
effects
such
as
early
exits,
exceptions,
non-local
transfers
of
control,
and
advanced
features
like
coroutines
or
backtracking.
It
also
provides
a
foundation
for
certain
compiler
optimizations
and
transformations,
since
control
flow
becomes
explicit
and
manipulable.
would
compute
x
+
1
and
then
call
k(x
+
1).
Chaining
multiple
operations
involves
nesting
continuations,
so
the
thread
of
control
is
explicit
in
the
code.
It
supports
modeling
complex
control
structures,
implementing
features
like
non-blocking
I/O
and
asynchronous
programming,
and
enabling
transformations
such
as
defunctionalization.
However,
CPS-style
code
can
become
verbose
and
harder
to
read,
so
it
is
usually
used
as
an
intermediate
representation
within
tools
rather
than
as
a
hand-written
programming
style
for
everyday
use.