Practical Foundations for Programming
Languages
Robert Harper
Carnegie Mellon University
[Version 1.30 of 03.15.2012.]
c 2012 by Robert Harper.
Copyright
All Rights Reserved.
The electronic version of this work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works
3.0 United States License. To view a copy of this license, visit
[Link]
or send a letter to Creative Commons, 171 Second Street, Suite
300, San Francisco, California, 94105, USA.
Preface
Types are the central organizing principle of the theory of programming
languages. Language features are manifestations of type structure. The
syntax of a language is governed by the constructs that define its types, and
its semantics is determined by the interactions among those constructs. The
soundness of a language designthe absence of ill-defined programs
follows naturally.
The purpose of this book is to explain this remark. A variety of programming language features are analyzed in the unifying framework of
type theory. A language feature is defined by its statics, the rules governing the use of the feature in a program, and its dynamics, the rules defining
how programs using this feature are to be executed. The concept of safety
emerges as the coherence of the statics and the dynamics of a language.
In this way we establish a foundation for the study of programming
languages. But why these particular methods? The main justification is
provided by the book itself. The methods we use are both precise and intuitive, providing a uniform framework for explaining programming language concepts. Importantly, these methods scale to a wide range of programming language concepts, supporting rigorous analysis of their properties. Although it would require another book in itself to justify this assertion, these methods are also practical in that they are directly applicable to
implementation and uniquely effective as a basis for mechanized reasoning.
No other framework offers as much.
Being a consolidation and distillation of decades of research, this book
does not provide an exhaustive account of the history of the ideas that inform it. Suffice it to say that much of the development is not original, but
rather is largely a reformulation of what has gone before. The notes at the
end of each chapter signpost the major developments, but are not intended
as a complete guide to the literature. For further information and alternative perspectives, the reader is referred to such excellent sources as Con (1984), Mitchell
stable (1986), Constable (1998), Girard (1989), Martin-Lof
(1996), Pierce (2002, 2004), and Reynolds (1998).
The book is divided into parts that are, in the main, independent of one
another. Parts I and II, however, provide the foundation for the rest of the
book, and must therefore be considered prior to all other parts. On first
reading it may be best to skim Part I, and begin in earnest with Part II,
returning to Part I for clarification of the logical framework in which the
rest of the book is cast.
Numerous people have read and commented on earlier editions of this
book, and have suggested corrections and improvements to it. I am particularly grateful to Andrew Appel, Iliano Cervesato, Lin Chase, Derek Dreyer,
Zhong Shao, and Todd Wilson for their extensive efforts in reading and
criticizing the book. I also thank the following people for their suggestions: Arbob Ahmad, Zena Ariola, Eric Bergstrome, Guy Blelloch, William
Byrd, Luis Caires, Luca Cardelli, Manuel Chakravarti, Richard C. Cobbe,
Karl Crary, Yi Dai, Daniel Dantas, Anupam Datta, Jake Donham, Favonia, Matthias Felleisen, Kathleen Fisher, Dan Friedman, Maia Ginsburg,
Byron Hawkins, Kevin Hely, Justin Hsu, Cao Jing, Salil Joshi, Gabriele
Keller, Scott Kilpatrick, Danielle Kramer, Akiva Leffert, Ruy Ley-Wild, Dan
Licata, Karen Liu, Dave MacQueen, Chris Martens, Greg Morrisett, Tom
Murphy, Aleksandar Nanevski, Georg Neis, David Neville, Doug Perkins,
Frank Pfenning, Jean Pichon, Benjamin Pierce, Andrew M. Pitts, Gordon
Plotkin, David Renshaw, John Reynolds, Carter Schonwald, Dale Schumacher, Dana Scott, Robert Simmons, Pawel Sobocinski, Daniel Spoonhower, Paulo Tanimoto, Peter Thiemann, Bernardo Toninho, Michael Tschantz,
Kami Vaniea, Carsten Varming, David Walker, Dan Wang, Jack Wileden,
Roger Wolff, Omer Zach, Luke Zarko, Yu Zhang. I am grateful to the students of 15312 and 15814 at Carnegie Mellon who have provided the
impetus for the preparation of this book and who have endured the many
revisions to it over the last ten years.
I thank the Max Planck Institute for Software Systems in Germany for
its hospitality and support. I also thank Espresso a Mano in Pittsburgh,
CB2 Cafe in Cambridge, and Thonet Cafe in Saarbrucken
for providing a
steady supply of coffee and a conducive atmosphere for writing.
This material is, in part, based on work supported by the National Science Foundation under Grant Nos. 0702381 and 0716469. Any opinions,
findings, and conclusions or recommendations expressed in this material
are those of the author(s) and do not necessarily reflect the views of the
National Science Foundation.
Robert Harper
Pittsburgh
March, 2012
Contents
Preface
iii
Judgements and Rules
Syntactic Objects
1.1 Abstract Syntax Trees . . . . . . . . . . . . . . . . . . . . . . .
1.2 Abstract Binding Trees . . . . . . . . . . . . . . . . . . . . . .
1.3 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
4
7
12
Inductive Definitions
2.1 Judgements . . . . . . . . . . . . . . . . . . . . .
2.2 Inference Rules . . . . . . . . . . . . . . . . . . .
2.3 Derivations . . . . . . . . . . . . . . . . . . . . . .
2.4 Rule Induction . . . . . . . . . . . . . . . . . . . .
2.5 Iterated and Simultaneous Inductive Definitions
2.6 Defining Functions by Rules . . . . . . . . . . . .
2.7 Modes . . . . . . . . . . . . . . . . . . . . . . . .
2.8 Notes . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
15
15
16
17
19
21
22
24
25
.
.
.
.
.
.
.
27
27
27
29
31
33
34
36
Hypothetical and General Judgements
3.1 Hypothetical Judgements . . . . .
3.1.1 Derivability . . . . . . . . .
3.1.2 Admissibility . . . . . . . .
3.2 Hypothetical Inductive Definitions
3.3 General Judgements . . . . . . . .
3.4 Generic Inductive Definitions . . .
3.5 Notes . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
viii
CONTENTS
II
Statics and Dynamics
37
Statics
4.1 Syntax . . . . . . . .
4.2 Type System . . . . .
4.3 Structural Properties
4.4 Notes . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
39
39
40
42
44
Dynamics
5.1 Transition Systems .
5.2 Structural Dynamics
5.3 Contextual Dynamics
5.4 Equational Dynamics
5.5 Notes . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
45
45
47
49
51
54
III
8
Type Safety
6.1 Preservation . .
6.2 Progress . . . .
6.3 Run-Time Errors
6.4 Notes . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
55
56
56
58
59
Evaluation Dynamics
7.1 Evaluation Dynamics . . . . . . . . . . . . . .
7.2 Relating Structural and Evaluation Dynamics
7.3 Type Safety, Revisited . . . . . . . . . . . . . .
7.4 Cost Dynamics . . . . . . . . . . . . . . . . .
7.5 Notes . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
61
61
63
64
65
66
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Function Types
67
Function Definitions and Values
8.1 First-Order Functions . . . . . . . . . . . . . . . .
8.2 Higher-Order Functions . . . . . . . . . . . . . .
8.3 Evaluation Dynamics and Definitional Equality
8.4 Dynamic Scope . . . . . . . . . . . . . . . . . . .
8.5 Notes . . . . . . . . . . . . . . . . . . . . . . . . .
V ERSION 1.30
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
69
70
71
73
74
76
R EVISED 03.15.2012
CONTENTS
9
Godels
T
9.1 Statics . . . . .
9.2 Dynamics . .
9.3 Definability .
9.4 Undefinability
9.5 Notes . . . . .
10 Plotkins PCF
10.1 Statics . . . .
10.2 Dynamics .
10.3 Definability
10.4 Notes . . . .
IV
ix
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
77
78
79
80
82
84
.
.
.
.
85
87
88
90
92
Finite Data Types
93
11 Product Types
11.1 Nullary and Binary Products . .
11.2 Finite Products . . . . . . . . . .
11.3 Primitive and Mutual Recursion
11.4 Notes . . . . . . . . . . . . . . . .
12 Sum Types
12.1 Nullary and Binary Sums
12.2 Finite Sums . . . . . . . .
12.3 Applications of Sum Types
12.3.1 Void and Unit . . .
12.3.2 Booleans . . . . . .
12.3.3 Enumerations . . .
12.3.4 Options . . . . . .
12.4 Notes . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
13 Pattern Matching
13.1 A Pattern Language . . . . . . . . . . . . . . . . . . .
13.2 Statics . . . . . . . . . . . . . . . . . . . . . . . . . . .
13.3 Dynamics . . . . . . . . . . . . . . . . . . . . . . . .
13.4 Exhaustiveness and Redundancy . . . . . . . . . . .
13.4.1 Match Constraints . . . . . . . . . . . . . . .
13.4.2 Enforcing Exhaustiveness and Redundancy .
13.4.3 Checking Exhaustiveness and Redundancy .
R EVISED 03.15.2012
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
95
96
97
98
100
.
.
.
.
.
.
.
.
101
101
103
104
104
105
106
106
108
.
.
.
.
.
.
.
109
110
110
112
114
114
116
117
V ERSION 1.30
CONTENTS
13.5 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
14 Generic Programming
14.1 Introduction . . .
14.2 Type Operators .
14.3 Generic Extension
14.4 Notes . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Infinite Data Types
121
121
122
122
125
127
15 Inductive and Co-Inductive Types
15.1 Motivating Examples . . . . .
15.2 Statics . . . . . . . . . . . . . .
15.2.1 Types . . . . . . . . . .
15.2.2 Expressions . . . . . .
15.3 Dynamics . . . . . . . . . . .
15.4 Notes . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
129
129
133
133
134
134
135
16 Recursive Types
16.1 Solving Type Isomorphisms
16.2 Recursive Data Structures .
16.3 Self-Reference . . . . . . . .
16.4 The Origin of State . . . . .
16.5 Notes . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
137
138
139
141
144
145
VI
.
.
.
.
.
Dynamic Types
147
17 The Untyped -Calculus
17.1 The -Calculus . . . . . . .
17.2 Definability . . . . . . . . .
17.3 Scotts Theorem . . . . . . .
17.4 Untyped Means Uni-Typed
17.5 Notes . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
149
149
150
153
155
156
18 Dynamic Typing
18.1 Dynamically Typed PCF . .
18.2 Variations and Extensions .
18.3 Critique of Dynamic Typing
18.4 Notes . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
159
159
163
166
167
V ERSION 1.30
R EVISED 03.15.2012
CONTENTS
xi
19 Hybrid Typing
19.1 A Hybrid Language . . . . . . . .
19.2 Dynamic as Static Typing . . . .
19.3 Optimization of Dynamic Typing
19.4 Static Versus Dynamic Typing . .
19.5 Notes . . . . . . . . . . . . . . . .
VII
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Variable Types
169
169
171
172
175
176
177
20 Girards System F
20.1 System F . . . . . . . . . . . . . . .
20.2 Polymorphic Definability . . . . .
20.2.1 Products and Sums . . . . .
20.2.2 Natural Numbers . . . . . .
20.3 Parametricity Overview . . . . . .
20.4 Restricted Forms of Polymorphism
20.4.1 Predicative Fragment . . . .
20.4.2 Prenex Fragment . . . . . .
20.4.3 Rank-Restricted Fragments
20.5 Notes . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
179
180
183
183
184
185
186
186
187
189
190
21 Abstract Types
21.1 Existential Types . . . . . . . . .
21.1.1 Statics . . . . . . . . . . .
21.1.2 Dynamics . . . . . . . . .
21.1.3 Safety . . . . . . . . . . . .
21.2 Data Abstraction Via Existentials
21.3 Definability of Existentials . . . .
21.4 Representation Independence . .
21.5 Notes . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
191
192
192
193
194
194
196
197
200
.
.
.
.
.
201
202
204
206
209
211
22 Constructors and Kinds
22.1 Statics . . . . . . . . . . .
22.2 Higher Kinds . . . . . .
22.3 Canonizing Substitution
22.4 Canonization . . . . . .
22.5 Notes . . . . . . . . . . .
R EVISED 03.15.2012
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
V ERSION 1.30
xii
VIII
CONTENTS
Subtyping
213
23 Subtyping
23.1 Subsumption . . . . . . . . . . .
23.2 Varieties of Subtyping . . . . .
23.2.1 Numeric Types . . . . .
23.2.2 Product Types . . . . . .
23.2.3 Sum Types . . . . . . . .
23.3 Variance . . . . . . . . . . . . .
23.3.1 Product and Sum Types
23.3.2 Function Types . . . . .
23.3.3 Quantified Types . . . .
23.3.4 Recursive Types . . . . .
23.4 Safety . . . . . . . . . . . . . . .
23.5 Notes . . . . . . . . . . . . . . .
24 Singleton Kinds
24.1 Overview . . . . .
24.2 Singletons . . . .
24.3 Dependent Kinds
24.4 Higher Singletons
24.5 Notes . . . . . . .
IX
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
215
216
216
216
217
218
218
219
219
220
221
223
225
.
.
.
.
.
227
228
229
231
235
237
Classes and Methods
25 Dynamic Dispatch
25.1 The Dispatch Matrix . . . .
25.2 Class-Based Organization .
25.3 Method-Based Organization
25.4 Self-Reference . . . . . . . .
25.5 Notes . . . . . . . . . . . . .
26 Inheritance
26.1 Class and Method Extension
26.2 Class-Based Inheritance . .
26.3 Method-Based Inheritance .
26.4 Notes . . . . . . . . . . . . .
V ERSION 1.30
239
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
241
242
244
245
247
249
.
.
.
.
251
251
253
254
255
R EVISED 03.15.2012
CONTENTS
xiii
257
Exceptions and Continuations
27 Control Stacks
27.1 Machine Definition . . . . . . . . . .
27.2 Safety . . . . . . . . . . . . . . . . . .
27.3 Correctness of the Control Machine .
27.3.1 Completeness . . . . . . . . .
27.3.2 Soundness . . . . . . . . . . .
27.4 Notes . . . . . . . . . . . . . . . . . .
28 Exceptions
28.1 Failures . . . . . . . . . . . .
28.2 Exceptions . . . . . . . . . .
28.3 Exception Type . . . . . . .
28.4 Encapsulation of Exceptions
28.5 Notes . . . . . . . . . . . . .
29 Continuations
29.1 Informal Overview . . . . .
29.2 Semantics of Continuations
29.3 Coroutines . . . . . . . . . .
29.4 Notes . . . . . . . . . . . . .
XI
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
259
259
261
262
264
264
266
.
.
.
.
.
267
267
269
271
272
275
.
.
.
.
277
277
279
281
285
Types and Propositions
30 Constructive Logic
30.1 Constructive Semantics
30.2 Constructive Logic . .
30.2.1 Provability . . .
30.2.2 Proof Terms . .
30.3 Proof Dynamics . . . .
30.4 Propositions as Types .
30.5 Notes . . . . . . . . . .
287
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
289
290
291
292
293
295
296
297
31 Classical Logic
31.1 Classical Logic . . . . . . . . . . . .
31.1.1 Provability and Refutability
31.1.2 Proofs and Refutations . . .
31.2 Deriving Elimination Forms . . . .
31.3 Proof Dynamics . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
299
300
300
302
305
306
R EVISED 03.15.2012
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
V ERSION 1.30
xiv
CONTENTS
31.4 Law of the Excluded Middle . . . . . . . . . . . . . . . . . . . 308
31.5 The Double-Negation Translation . . . . . . . . . . . . . . . . 310
31.6 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
XII
Symbols
313
32 Symbols
32.1 Symbol Declaration . . . . . .
32.1.1 Scoped Dynamics . . .
32.1.2 Scope-Free Dynamics
32.2 Symbolic References . . . . .
32.2.1 Statics . . . . . . . . .
32.2.2 Dynamics . . . . . . .
32.2.3 Safety . . . . . . . . . .
32.3 Notes . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
315
316
317
318
319
319
320
320
321
33 Fluid Binding
33.1 Statics . . . . . .
33.2 Dynamics . . .
33.3 Type Safety . . .
33.4 Some Subtleties
33.5 Fluid References
33.6 Notes . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
323
323
324
325
326
328
330
34 Dynamic Classification
34.1 Dynamic Classes . . . . . . . . .
34.1.1 Statics . . . . . . . . . . .
34.1.2 Dynamics . . . . . . . . .
34.1.3 Safety . . . . . . . . . . . .
34.2 Class References . . . . . . . . . .
34.3 Definability of Dynamic Classes .
34.4 Classifying Secrets . . . . . . . .
34.5 Notes . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
331
332
332
333
334
334
335
336
337
XIII
State
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
339
35 Modernized Algol
341
35.1 Basic Commands . . . . . . . . . . . . . . . . . . . . . . . . . 341
35.1.1 Statics . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
V ERSION 1.30
R EVISED 03.15.2012
CONTENTS
xv
35.1.2 Dynamics . . . . . . . . . . . . . . .
35.1.3 Safety . . . . . . . . . . . . . . . . . .
35.2 Some Programming Idioms . . . . . . . . .
35.3 Typed Commands and Typed Assignables .
35.4 Notes . . . . . . . . . . . . . . . . . . . . . .
36 Assignable References
36.1 Capabilities . . . . . . . . .
36.2 Scoped Assignables . . . . .
36.3 Free Assignables . . . . . . .
36.4 Safety for Free Assignables .
36.5 Benign Effects . . . . . . . .
36.6 Notes . . . . . . . . . . . . .
XIV
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
343
345
346
348
351
.
.
.
.
.
.
353
354
355
357
360
362
364
Laziness
37 Lazy Evaluation
37.1 By-Need Dynamics .
37.2 Safety . . . . . . . . .
37.3 Lazy Data Structures
37.4 Suspensions . . . . .
37.5 Notes . . . . . . . . .
365
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
367
368
372
374
375
377
38 Polarization
38.1 Positive and Negative Types
38.2 Focusing . . . . . . . . . . .
38.3 Statics . . . . . . . . . . . . .
38.4 Dynamics . . . . . . . . . .
38.5 Safety . . . . . . . . . . . . .
38.6 Notes . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
379
380
381
382
384
385
386
XV
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Parallelism
39 Nested Parallelism
39.1 Binary Fork-Join . . . . . . . . . . . .
39.2 Cost Dynamics . . . . . . . . . . . .
39.3 Multiple Fork-Join . . . . . . . . . .
39.4 Provably Efficient Implementations .
39.5 Notes . . . . . . . . . . . . . . . . . .
R EVISED 03.15.2012
387
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
389
390
393
396
398
402
V ERSION 1.30