Book contents
- Frontmatter
- Contents
- Preface
- Part I Judgments and Rules
- Part II Statics and Dynamics
- Part III Function Types
- Part IV Finite Data Types
- Part V Infinite Data Types
- Part VI Dynamic Types
- Part VII Variable Types
- Part VIII Subtyping
- Part IX Classes and Methods
- Part X Exceptions and Continuations
- 27 Control Stacks
- 28 Exceptions
- 29 Continuations
- Part XI Types and Propositions
- Part XII Symbols
- Part XIII State
- Part XIV Laziness
- Part XV Parallelism
- Part XVI Concurrency
- Part XVII Modularity
- Part XVIII Equational Reasoning
- Part XIX Appendix
- Bibliography
- Index
29 - Continuations
from Part X - Exceptions and Continuations
Published online by Cambridge University Press: 05 February 2013
- Frontmatter
- Contents
- Preface
- Part I Judgments and Rules
- Part II Statics and Dynamics
- Part III Function Types
- Part IV Finite Data Types
- Part V Infinite Data Types
- Part VI Dynamic Types
- Part VII Variable Types
- Part VIII Subtyping
- Part IX Classes and Methods
- Part X Exceptions and Continuations
- 27 Control Stacks
- 28 Exceptions
- 29 Continuations
- Part XI Types and Propositions
- Part XII Symbols
- Part XIII State
- Part XIV Laziness
- Part XV Parallelism
- Part XVI Concurrency
- Part XVII Modularity
- Part XVIII Equational Reasoning
- Part XIX Appendix
- Bibliography
- Index
Summary
The semantics of many control constructs (such as exceptions and coroutines) can be expressed in terms of reified control stacks, a representation of a control stack as an ordinary value. This is achieved by allowing a stack to be passed as a value within a program and to be restored at a later point, even if control has long since returned past the point of reification. Reified control stacks of this kind are called continuations; they are values that can be passed and returned at will in a computation. Continuations never “expire,” and it is always sensible to reinstate a continuation without compromising safety. Thus continuations support unlimited “time travel”—we can go back to a previous point in the computation and then return to some point in its future, at will.
Why are continuations useful? Fundamentally, they are representations of the control state of a computation at a given point in time. Using continuations we can “checkpoint” the control state of a program, save it in a data structure, and return to it later. In fact, this is precisely what is necessary to implement threads (concurrently executing programs)—the thread scheduler must be able to checkpoint a program and save it for later execution, perhaps after a pending event occurs or another thread yields the processor.
- Type
- Chapter
- Information
- Practical Foundations for Programming Languages , pp. 231 - 238Publisher: Cambridge University PressPrint publication year: 2012