The Revised Report

on the

Syntactic Theories of Sequential Control and State

Matthias Felleisen Department of Computer Science

Rice University Houston, TX 77251-1892

Robert Hieb

Computer Science Department

Indiana University Bloomington, IN 47405

Rice University Technical Report # 100-89 to appear in: Theoretical Computer Science 1991

The Revised Report on the Syntactic Theories of Sequential Control and State

Matthias Felleisen^{∗} Department of Computer Science, Rice University, Houston, TX 77251-1892

Robert Hieb^{†} Computer Science Department, Indiana University, Bloomington, IN 47405

Abstract

The syntactic theories of control and state are conservative extensions of the λ_{v}-calculus for equational reasoning about imperative programming facilities in higher-order languages. Unlike the simple λ_{v}-calculus, the extended theories are mixtures of equivalence relations and compatible congruence relations on the term language, which significantly complicates the reasoning process. In this paper we develop fully compatible equational theories of the same imperative higher-order programming languages. The new theories subsume the original calculi of control and state and satisfy the usual Church-Rosser and Standardization Theorems. With the new calculi, equational reasoning about imperative programs becomes as simple as reasoning about functional programs.

1 The syntactic theories of control and state

Most λ-calculus-based programming languages provide imperative programming facilities such as assignment statements, exceptions, and continuations. Typical examples are ML [16], Scheme [19], and Common Lisp [20]. While these additions add expressive power and increase the efficiency of programs, they also appear to invalidate the simple reduction rules and equational reasoning of the λ-calculus that make functional programming so appealing. In two previous papers [8, 9], we have shown that there are conservative extensions of Plotkin’s λ_{v}-calculus [18] for such programming languages, and that it is possible to reason about programs in extended functional languages in an equational style.

The main difference between the simple lambda-calculi and its extended versions is a distinction between two classes of equations: equations for ordinary expressions and equations for whole programs. The reason for this distinction is the need to arrange the effects of assignments and jumps in the appropriate order. For example, a program like x := 3; y := x + 1 is equivalent to the program y := 4, yet the subexpression x := 3; y := x + 1 cannot be replaced by y := 4 because the context in which the former expression occurs may contain further references to x and these references must be able to perceive the assignment to x. Still, the calculi satisfy relatively simple variants of the Church-Rosser and Standardization properties. Most importantly, they satisfy most of Plotkin’s [18] criteria for a correspondence between a programming language and a reduction-based calculus:

∗Supported in part by NSF grants CCR 88-07520 and 89-17022, and DARPA/NSF grant CCR 87-20277.

†Supported in part by NSF grant CCR 88-03432.

(1) the standard derivations of the calculi yield the same value for a program as the operational semantics, and

(2) a subset of the calculi equations for ordinary expressions are operationally sound.

The first property is important because a programmer can use the relatively simple reduction system to determine the value of an imperative higher-order program by rewriting the program until it becomes a value. The second property is a basis for program transformations and program correctness proofs. However, as the restriction in (2) indicates, the calculi are complicated equational theories because some equivalences are not equations in the usual sense. This distinction is unnatural and leads to problems in reasoning about equational properties of programs.

One way to simplify the equational theories for an imperative programming language is to modify the programming language. For example, we recently showed that by adding a control delimiter facility to the λ-calculus extended with control operators, we can simplify the calculus and get a more elegant relationship between the language and its calculus [6]. But, although this proposal provides a good example of how calculus design can influence and improve language design, it does not alleviate the need for better techniques for reasoning about existing languages. Languages such as Scheme, ML, and Common Lisp have grown through practical experiences and support practical applications, and they need calculi that are tuned towards their specific needs.

The solution to the problem is to relax Plotkin’s first correspondence criterion. More precisely, we no longer require that the standard derivation of the programming language calculi terminate in a value when the machine produces a value for a program. Instead, we allow the standard derivation to produce some other kind of term that is recognizable as a final answer. For both kinds of imperative extensions, i.e., control operators and assignments, the result is a simple equational calculus for imperative, higher-order programming languages that can prove the same set of observational equivalences as the old calculus but with an elegant axiomatic basis. Indeed, reasoning with the new calculi is as simple as reasoning with the traditional λ-calculus.

In the next section, we briefly summarize Plotkin’s work on the λ_{v}-calculus since it constitutes the basis of our research. Sections 3 and 4 present our new theories of control and state, respectively. These sections begin by briefly introducing our old calculi, which provide machine-independent semantics for the languages and standards against which to measure the new theories. Next, these sections introduce the new calculi and analyze the relationships between the old and new calculi. The fifth section describes the merger of the two theories. Finally we discuss related work and some implications of our work for an alternative denotational semantics for extended functional languages.

2 The λ-value-calculus

The expression language Λ of the λ-calculus and the λ_{v}-calculus [2, 3, 18] is the union of a set of values and expression juxtapositions:

e ::= v | (e e).

The set of values is the collection of basic constants (b ∈ BConsts) and functional constants (f ∈ FConsts), variables (x ∈ Vars) and λ-abstractions:

v ::= b | f | x | λx.e.

Constants correspond to built-in algebraic language primitives like numbers and booleans and (mathematical) functions on them; identifiers are placeholders for values; and λabstractions are call-by-value procedures. Expression juxtaposition denotes function application.

The only binding construct in the programming language is λ-abstraction. The set of closed expressions, Λ^{0}, is the set of all expressions with no free variables; Values^{0} is the set of closed values. We adopt Barendregt’s [2] conventions on bound variables and abstractions:

• Bound variables are always distinct from free variables in the various expressions of mathematical definitions and claims.

• Abstractions that only differ by a renaming of bound variables are identified, e.g., λx.x ≡ λy.y.

The expression e[x ← e_{1}] is the result of substituting the expression e_{1} for a free variable x in the expression e.

An important parameter of the language definition is the set of constants and its interpretation. Following Plotkin [18], we assume that the behavior of constants is specified by a partial function from functional and basic constants to closed values:

δ : FConsts × BConsts → Values^{0}.

In the mid-60’s, Landin [11, 12] illustrated in a series of papers that Λ is an interesting and powerful programming language. Most importantly, he showed how a simple stackbased calculator for algebraic expressions could be extended to the abstract SECD-machine for evaluating complete Λ-programs. From a programmer’s perspective, the SECD-machine is an interpreter that implements a partial function from programs to answers, where the former are closed expressions and the latter are closed values:

eval_{SECD} : Λ^{0} → Values^{0}.

The use of Λ as a programming language with an operational semantics and as the term language for Church’s λ-calculus [3] raises the natural question of how the two concepts correspond to each other. Plotkin [18] provided the answer by defining the λ_{v}-calcu-lus, which matches the evaluation function eval_{SCED}, and by providing a modified SECDmachine, which implements the λ-calculus correctly in the above sense of a Landin-style interpreter. The original SECD-semantics and the λ_{v}-calculus precisely model the callby-value parameter-passing technique that is now predominant in the functional subsets of programming languages. Besides being easy to implement, call-by-value provides an obvious order of evaluation, which facilitates the addition of imperative features. There is, however, no theoretical reason for choosing one over the other, even in the presence of control operators and assignments.

The λ_{v}-calculus is an equational theory about Λ. More precisely, it is a set of equations that is based on a set of term relations on Λ. The two basic relations, notions of reduction, are:

\begin{matrix}fa & ⟶ & δ(f, a) & (δ) \\ (λx.e)v & ⟶ & e[x ← v]. & (β_{v}) \end{matrix}

The equational theory λ_{v} is the smallest congruence relation generated from the above relations. For the formal definition, we rely on the concept of a term context, which are expressions with a hole ([ ]) at the place of a subexpression:

C ::= [ ] | (e C) | (C e) | (λx.C).

The expression C[e] stands for the result of putting the expression e into the hole of the context C , which may bind free variables in e.

Given the notions of reduction and the definition of contexts, the definition of λ_{v} is straightforward.

Definition 2.1. (λ_{v}) The basic notion of reduction is

v = δ ∪ β_{v}.

The one-step v-reduction ⟶_{v} is the compatible closure of v: e ⟶_{v} e′ if (p, q) ∈ v, e ≡ C[p], and e′ ≡ C[q] for some expressions p and q and context C. The v-reduction is denoted by ⟶ ⟶_{v} and is the reflexive, transitive closure of ⟶_{v}; =_{v} is the smallest equivalence relation generated by ⟶_{v}. If e_{1} =_{v} e_{2}, we write λ_{v} ⊢ e_{1} = e_{2}.

The λ_{v}-calculus has the same characteristic properties as Church’s original λ-calculus. First, the defining notion of reduction, v, is Church-Rosser, i.e., the v-reduction satisfies the diamond property.

Theorem 2.2 (Plotkin) If e⟶ ⟶_{v} e_{1} and e⟶ ⟶_{v} e_{2}, then there exists an expression e′ such that e_{1} ⟶ ⟶_{v} e′ and e_{2} ⟶ ⟶_{v} e′.

Second, for every sequence of (single) reduction steps from one term to another, there is a canonical sequence of steps between the same terms that can be found algorithmically. This idea is important for an analysis of the correspondence between a calculus and an abstract machine. While it is easy to see that e ⟶ ⟶_{v} v if eval_{SECD}(e) = v, the inverse is not correct. If e ⟶ ⟶_{v} v and v is a λ-abstraction, then there are possibly many different values to which e reduces, yet eval_{SECD}, the interpreter, can only yield one value for e. To determine this value via a sequence of reductions, we need canonical reductions and an algorithm to compute them.

To describe the basis of the algorithm and to state the corresponding theorem, we need some definitions. An evaluation context is a special kind of context. The hole of an evaluation context is in such a position that a δ- or β_{v}-redex inserted in the hole is the leftmost-outermost redex that is not inside of a λ-abstraction. We let E range over the set of evaluation contexts and define it with the following grammar:

E ::= [ ] | (v E) | (E e).

Given the definition of an evaluation context, we say that e standard reduces to e′ if the reduction occurs in an evaluation context. In other words, a standard reduction function always picks the leftmost-outermost v-redex outside the scope of a λ-expression. It is undefined on values.

Definition 2.3. (Standard Reduction Function) The standard reduction function maps e to e′, e ⟼_{v} e′, if for some evaluation context E, e ≡ E[p], e′ ≡ E[q] and (p, q) ∈ v. We use ⟼_{v}^{∗} to denote the transitive closure of the standard reduction function.

The concept of standard reduction sequences generalizes the idea of a standard reduction function such that standard reductions become applicableto arbitrary term positions. A standard reduction sequence also permits incomplete reduction sequences that may choose not to reduce a leftmost-outermost redex for the rest of the sequence.

Definition 2.4. (Standard Reduction Sequences) The set of standard reduction sequences is defined as follows:

1. Every constant and variable is a standard reduction sequence.

2. If e_{1},…, e_{n} is a standard reduction sequence, then so is λx.e_{1},…, λx.e_{n}.

3. If p_{1},…, p_{n} and q_{1},…, q_{m} are standard reduction sequences, then so is

p_{1}q_{1}, p_{2}q_{1},…, p_{n}q_{1}, p_{n}q_{2},…, p_{n}q_{m}.

4. If e_{1},…, e_{n} is a standard reduction sequence and e ⟼_{v} e_{1}, then e, e_{1},…, e_{n} is a standard reduction sequence.

We can now formalize a Curry-Feys-style Standardization Theorem.

Theorem 2.5 (Plotkin) e ⟶ ⟶_{v} e′ if and only if there is a standard reduction sequence e,…, e′.

Together, the Church-Rosser and Standard Reduction Theorems show that there is a perfect correspondence between the SECD-evaluation function and the standard reduction function.

Theorem 2.6 (Plotkin) Let e, v be closed terms in Λ. Then, e ⟼_{v}^{∗} v if and only if eval_{SECD}(e) = v.

In other words, the SECD-machine terminates and returns a value for a program if and only if the program standard reduces to the same value. It is therefore possible to define the evaluation function via the standard reduction function, ignoring the details of the actual machine:

eval_{v}(e) ≡^{df} v iff e ⟼_{v}^{∗} v.

After determining that reductions in the calculus correspond to evaluations on a machine, the question remains what equations on the calculus mean for a programmer. To understand this relationship, we recall that a programmer can only observe the effects of entire programs via the evaluator. Thus, to compare expressions as black boxes, a programmer must rely on those equivalences that the evaluation function can validate for all programs in which the expression can occur. This argument naturally leads to the definition of the operational equivalence relation.

Definition 2.7. (Operational Equivalence) Two terms, e and e′, are operationally equivalent, e ≃_{v} e′, if and only if they are indistinguishable in all program contexts C :

eval_{v}(C[e]) terminates iff eval_{v}(C[e′]) terminates

and

eval_{v}(C[e]) = b iff eval(C[e′]) = b

for some basic constant b.

Plotkin [18] showed that the λ_{v}-calculus is sound with respect to operational equivalence.

Theorem 2.8 (Plotkin) If λ_{v} ⊢ e = e′ then e ≃_{v} e′. The inverse direction does not hold.

Theorems 2.5 and 2.8 are the basis of a formal correspondence relation between programming languages and calculi. They stipulate that

1. a calculus can evaluate a program in the same way as an independently given operational semantics; and

2. the equations of a calculus imply the interchangeability of expressions in arbitrary contexts.

These two criteria are the basis for any further development of programming language calculi.

3 Theories of control

The language Λ_{c} for programming with procedural and control abstractions is an extension of Λ with a set of C-applications of the form (Ce):

e ::= v | (ee) | (Ce).

A C-application applies its subexpression to an abstraction of the current control context, the continuation. The application takes place in the empty control context, the halt continuation. A continuation has the same first-class status as a λ-abstraction; upon invocation, it discards the control context of the application and resumes the abstracted control context with its argument.

This notion of control abstraction is derived from the treatment of continuations in the programming language Scheme [19]. However, although the continuation created by a C-application acts just like a continuation created by the Scheme continuation constructor call/cc, a C-application differs from a call/cc application in that the former aborts the current control context, whereas the latter leaves the current control context intact. This abortive affect allows us to define an abort abstraction as an abbreviation of a C-application whose subexpression is a procedure that ignores its argument:

A e ≡^{df} C(λd.e) where d ∉ FV (e).

The effect of (A e) is an abort of the program evaluation. It discards the current control context and returns the value of its subexpression as the final value of the program. This abbreviation is used to simplify the reduction rules for C-applications.

Other than the introduction of C-applications, the syntax of Λ is adopted mutatis mutandis. The definition of the set of values retains its shape, even though subexpressions are in the extended language Λ_{c}:

v ::= b | f | x | λx.e.

Similarly, the specification of the set of evaluation contexts stays the same:

E ::= [ ] | (v E) | (E e),

but it now denotes the set of evaluation contexts whose subexpressions are in the extended language Λ_{c}.

The following subsection briefly presents our original theory of control abstractions with an emphasis on the set of safe equations; for a more complete description, we refer the reader to the earlier report [9]. The second subsection contains the development of a finite axiomatization of the theory of safe equations. The Plotkin-style correspondence theorem relies on a proof of equivalence between the two calculi and on the idea that the old calculus is an acceptable specification of the semantics of Λ_{c}. The final subsection presents two interesting extensions of the equational theory.

3.1 A syntactic theory of control abstractions

Originally we derived the syntactic theory of control from an abstract operational semantics based on Landin’s SECD-machine [7]. Eliminating all non-program text components from the machine shows that the concept of “current continuation” is equivalent to the notion of evaluation context. The machine transition rules for abstracting a control state naturally lead to two term relations that gradually lift a C-application to the top of an evaluation context while encoding the context as an abstraction.

When the C-expression, Ce, occurs as the function part of an application, (Ce)e′, its immediate continuation is the application of a yet-unknown function f to the expression e′. The rest of the continuation, k, is the continuation of the entire application. Composing the two pieces, k(fe′), yields the functional part of the continuation of Ce, which in turn is the argument for e. Since this continuation must abort its context upon invocation, we wrap this expression in an A-application. To obtain the outer part of the continuation, we use another C-application:

(C e)e′ ⟶ C(λk.e (λx.A(k (xe′)))).

Similarly, when the control expression occurs as the argument part of an application, the abstraction of the control context applies the known function to an unknown argument, passing the result to the continuation of the entire application:

v(C e) ⟶ C(λk.e (λx.A(k (vx)))).

The assumption that the left part of the application is a value reflects the left-to-right evaluation order of the underlying language.

To facilitate the formal definition and future reference to the above rules, we introduce the notion of a singular evaluation context:

E^{s} ::= (v [ ]) | ([ ] e).

Using singular evaluation contexts, one definition schema suffices for specifying both of the above reduction relations for Λ_{c}:

E^{s}[C e] ⟶ C(λk.e (λx.A(k E^{s}[x]))).  (C_{lift})

The relation for lifting C-applications gives rise to an extended notion of reduction:

c = δ ∪ β_{v} ∪ C_{lift}.  (c)

This notion of reduction defines a full reduction relation and a congruence relation in the usual way. It is Church-Rosser and has Curry-Feys-style standard reduction sequences. The symbol ⟼_{c} denotes the standard reduction function for c. The respective theorems and proofs are straightforward adaptations of the proofs of Plotkin’s corresponding theorems. We use λ_{v}-C(c) ⊢ e = e′ if e =_{c} e′.

For a complete simulation of an abstract machine for Λ_{c}, the reduction based on c is insufficient because C-applications get stuck at the top of the program. We therefore introduce a computation rule that maps a C-application at the top of the program into an application of its subterm to the halt continuation (λx.Ax):

C e ▷ e(λx.Ax).  (C_{T})

Together with the extended reduction ⟶ ⟶_{c}, the computation rule forms a computation relation

▷_{c} = ⟶ ⟶_{c} ∪ C_{T} .

The computation relation satisfies the diamond property, i.e., if e ▷_{c} e_{1} and e ▷_{c} e_{2}, then for some e′, e_{1} ▷_{c} e′ and e_{2} ▷_{c} e′. But, since C_{T} only applies to entire programs, the computation relation cannot satisfy the full Church-Rosser property. Similarly, there are standard computation sequences, which are weak forms of standard reduction sequences. The computation relation generates an equivalence relation on programs, which we refer to as =^{▷}_{c}. We also write λ_{v}-C^{▷} ⊢ e = e′ if e =^{▷}_{c} e′. Based on the diamond property of the computation relation and the Church-Rosser property of the reduction c, it is easy to show that the theory λ_{v}-C^{▷} is a conservative extension of λ_{v}.

The standard computation function is a generalization of the notion of a standard reduction function and always performs the leftmost-outermost computation step. Like the standard reduction function, it is undefined on values.

Definition 3.1. (c-Standard Computation Function) The standard computation function maps a program e to a program e′, e ⟼^{▷}_{c} e′, if e standard reduces to e′ or if e computes to

e′: ⟼^{▷}_{c} = ⟼_{c} ∪ C_{T}.

The standard computation function faithfully simulates evaluation on a machine for Λ_{c}, i.e., we can use it to define a semantics instead of a machine with complex states:

eval_{c}(e) = v  if  e ⟼^{▷}_{c}^{∗} v.

This, in turn, gives rise to an operational equivalence relation in the usual manner. A Λ_{c}-expression e is operationally equivalent to e′, e ≃_{c} e′, if and only if the two are indistinguishable in the sense of Definition 2.7 relative to all Λ_{c}-program contexts.

From the design of the control calculus, it follows that congruences generated by creduction are operationally sound, but, due to their context-sensitivity, equations based on the computation relation are not.

Theorem 3.2 ([9]) Let e and e′ be in Λ_{C}.

(i) If λ_{v}-C(c) ⊢ e = e′ then e ≃_{c} e′.

(ii) λ_{v}-C^{▷} ⊢ e = e′ does not imply e ≃_{c} e′.

Fortunately, it is possible to factor out a large subset of equations in λ_{v}-C^{▷} that are operationally sound: the safe equations.

Definition 3.3. (C-Safe Equations) An equation e =^{▷}_{c} e′ is safe if and only if it holds in all evaluation contexts: λ_{v}-C^{▷} ⊢ E[e] = E[e′] for all E.

Operationally, the two terms of a safe equation have the same control effects. In order to enrich the set of safe equations we also permit the use of safe equations in the safeness proof of an equation. We use λ_{v}-C-safe to refer to the equational theory generated by safe equations. The safe theory is again a conservative extension of λ_{v} and, more importantly, reduces reasoning about operational equivalence from the set of all contexts to the set of evaluation contexts.

Theorem 3.4 ([9]) If λ_{v}-C-safe ⊢ e = e′ then e ≃_{c} e′.

In summary, the calculus of control abstractions is like an ordinary λ-calculus with Church-Rosser and Standardization Theorems. Moreover, it closely corresponds to the programming language definition for Λ_{c}. If we need to evaluate a program, the standard computation will produce the correct value; for proving operationally sound equations, we often must work in the theory of safe equations. In general, we will be more interested in the latter than the former because most interesting properties of programs are characterized by safe equations. Unfortunately, working with the theory of safe equations is not as easy as working with the λ-calculus since it is not a simple axiomatic theory with a finite set of axioms or axiom schemas but a theory based on a filtered subset of another theory, λ_{v}-C^{▷}. We introduce a simple axiomatic characterization of safeness in the next subsection.

3.2 An axiomatic basis for safe equations

The disturbing element in the calculus of control abstractions is the rule C_{T}. The purpose of the rule is to replace a C-application (Ce) at the root of a program with an application of e to the halt continuation. For an axiomatic characterization of safe equations, we must find a way of replacing this special relation with simple notions of reduction that approximate its effect.^{1}

A partial solution is to leave C-applications at the root of the program alone and to continue with the evaluation of the subexpression. More precisely, when a C-application reaches the root of the program after a number of C_{lift} reductions, it has the shape (Cλk.e), and an evaluation may continue with e. But this clearly leads to an accumulation of C-applications at the root of a program. By observing that the outermost C-application removes the current continuation and that therefore the next C-application’s continuation is the halt continuation, we are led to a rule that captures the idempotency of the abort action of C-applications:

C(λk.C e) ⟶ C(λk.e(λx.Ax)).  (C_{idem})

The only exception to this reasoning is the case where the program is already a C-application and the subexpression is not an abstraction. We therefore need a rule for transforming an arbitrary subexpression of a C-application into a λ-abstraction. The task of this abstraction is to receive a continuation and to apply the subexpression to it. A first attempt at the rule could be

C e ⟶ C(λk.e k).

Unfortunately, this version is not strong enough. If, for example, e is a λ-abstraction that eventually causes an application of k to some value, the reduction would be stuck and no further evaluation would be possible. The solution is to replace k by (λx.A(kx)) so that an application of the continuation can initiate a program abort. Putting things together, the additional rule becomes

C e ⟶ C(λk.e (λx.A(k x))).  (C_{top})

Although a C_{idem} redex is also a C_{top} redex, this ambiguity causes no problem: by imposing an appropriate condition on the standard reduction function (see below), it is still possible to emulate a deterministic machine.

Together, the two new relations, C_{idem} and C_{top}, can closely simulate the top-level rule of λ_{v}-C^{▷}. Indeed, the entire system of c-reduction, C_{idem}, and C_{top} suffices for simulating a complete evaluation. To begin, we introduce the notion of reduction

1Tim Griffin independently and simultaneously discovered another solution while studying the connection between a typed variant of the control calculus and classical logic [10]. He proposes to restrict the set of programs to expressions of the form C(λk.ke) and to use C_{idem} as a replacement for C_{T}.

d = c ∪ C_{idem} ∪ C_{top}.

As usual, we let ⟶_{d} and ⟶ ⟶_{d} stand for the respective one-step reduction and its transitive closure. Furthermore, we write λ_{v}-C(d) ⊢ e = e′ if e =_{d} e′. Next we characterize the relationship between standard computation and the new reduction system with three lemmas. Clearly, the new system subsumes the standard computations that are entirely based on c-reductions.

Lemma 3.5 If e ⟼^{▷}_{c}^{∗} e′ without use of C_{T} then e ⟶ ⟶_{d} e′.

Proof. Suppose e ⟼^{▷}_{c}^{∗} e′ without use of C_{T}. Then e ⟼_{c}^{∗} e′ and therefore e ⟶ ⟶_{d} e′. □

Given the operational motivation behind the introduction of C_{idem}, it should also be obvious that once a C-application is at the root of the program the evaluation proceeds as before.

Lemma 3.6 If e ⟼^{▷}_{c}^{∗} e′ then C(λk.e) ⟶ ⟶_{d} C(λk.e′).

Proof. Since C_{idem} is essentially an instance of C_{T} inside of the context C(λk.[ ]), every computation step in the old derivation is a reduction step inside of C(λk.[ ]) in the revised calculus. The rest follows by transitivity. □

Finally, if an evaluation in λ_{v}-C^{▷} uses a top-level step, there is no equivalent step in the new reduction system. However, based on the above lemmas, we can show that the rest of the evaluation in λ_{v}-C^{▷} can be simulated, and that there is always a close relationship between the respective terms in the two sequences.

Lemma 3.7 If e ⟼^{▷}_{c}^{∗} e′ with at least one C_{T} -step, then e ⟶ ⟶_{d} C(λk.e′_{k}), where e′_{k} may be converted to e′ by replacing all occurrences of (ku) with u for arbitrary values u.

Proof. By assumption, the derivation for e ⟼^{▷}_{c}^{∗} e′ must contain a first step using C_{T}:

e ⟼_{c}^{∗} Ce_{1} ▷ \underline{(e_{1}(λx.A^{†}x))} ⟼^{▷}_{c}^{∗} e′.

We tag this first, newly-created halt continuation with a dagger † so that we can track it through the rest of the computation and distinguish its occurrence in the final answer.

By Lemma 3.5, the first part of the above derivation is easily simulated in the new system:

e ⟶ ⟶_{d} Ce_{1} ⟶_{d} C(λk.\underline{e_{1}(λx.A^{†}(k x))}).

Since replacing (kx) with x in the underlined term yields the underlined term in the previous derivation, the underlined terms satisfy the desired relationship.

To complete the proof, it suffices to show that the invariant is preserved by all steps following the first top-level step. For this, we consider two cases.

1. Assume that the tagged continuation is not applied to a value during the rest of the computation. It is easy to see that in λ_{v}-C^{▷} the second half of the derivation,

e_{1}(λx.A^{†}x) ⟼^{▷}_{c}^{∗} e′,

can be transformed into the derivation

e_{1}y ⟼^{▷}_{c}^{∗} e′_{y} where e′ ≡ e′_{y}[y ← (λx.A^{†}x)].

By Lemma 3.6, it follows that

C(λk.e_{1}y) ⟶ ⟶_{d} C(λk.e′_{y}),

and, by replacing free y with (λx.A^{†}(k x)),

C(λk.e_{1}(λx.A^{†}(k x))) ⟶ ⟶_{d} C(λk.e′_{y}[y ← (λx.A^{†}(k x))]).

Again, a replacement of (kx) with x throughout e′_{y}[y ← (λx.A^{†}(k x))] yields e′_{y}[y ← (λx.A^{†}x)], which is e′.

2. Assume that the tagged continuation is applied to a value for a first, and last, time:

e_{1}(λx.A^{†}x) ⟼^{▷}_{c}^{∗} E[(λx.A^{†}x)v] ⟼^{▷}_{c} \underline{E[A^{†}v]} ⟼^{▷}_{c}^{∗} e′.

By the same reasoning as in the first case, there must be an evaluation context E_{y} and a value v_{y} such that

C(λk.e_{1}(λx.A^{†}(k x))) ⟶ ⟶_{d} C(λk.E_{y}[yv_{y}][y ← (λx.A^{†}(k x))])
⟶_{d} C(λk.\underline{E_{y}[A^{†}(kv_{y})][y ← (λx.A^{†}(k x))]}),

where E ≡ E_{y}[y ← (λx.A^{†}x)] and v ≡ v_{y}[y ← (λx.A^{†}x)]. Substituting v_{y} for (kv_{y}) and x for (kx) in the underlined term yields E_{y}[(A^{†}v_{y})][y ← (λx.A^{†}x)], which is the underlined term E[A^{†}v] above. The corresponding terms in the two derivation sequences still satisfy the desired invariant.

The rest of the standard computation sequence in λ_{v}-C^{▷} can only eliminate some or all of the evaluation context E. These steps are easily mimicked in the new calculus without violating the desired relationship. □

fa ⟶ δ(f, a)  (δ)
(λx.e)v ⟶ e[x ← v]  (β_{v})
E^{s}[C e] ⟶ C(λk.e (λx.A(k E^{s}[x])))  (C_{lift})
C e ⟶ C(λk.e (λx.A(k x)))  (C_{top})
C(λk.(C e)) ⟶ C(λk.e(λx.Ax))  (C_{idem})

Figure 1: The revised syntactic theory of control

In summary, Lemmas 3.5 through 3.7 show that if a program has a value according to eval_{c}, then the new calculus can reduce the program to a recognizably equivalent expression. The essential difference is that the reductions in λ_{v}-C(d) “remember” whether or not the computation used any control operations. Thus, the answer in the new theory may be a simple value, v, a C-application that abstracts over a value, C(λk.v), or a C-application that abstracts over the application of a continuation variable to a value, C(λk.k v). In the first case, v is the same answer the evaluation function eval_{c} would produce; in the latter two cases, the body of the C-application may be converted to the expected answer by replacing all occurrences of (kv) with v.

More importantly, the proofs of the above lemmas also show that the new calculus basically reduces programs to answers with standard reduction steps. More precisely, an evaluation with the new rules begins with standard reduction steps based on the relation c. If this yields a value, the evaluation is finished. If not, it reaches a C-application, in which case it employs a single C_{top}-step, followed by a number of standard reduction steps based on c possibly intermingled with C_{idem} reductions on the complete program. If this yields a C-application of the above form, the evaluation stops and produces an answer. We abstract this process in an evaluation function.

Definition 3.8. (d-Evaluation) Let C(λk.e) ⟼_{idem} C(λk.e′) if (C(λk.e), C(λk.e′)) ∈ C_{idem} or e ⟼_{c} e′. Let v and v_{y} be values such that v ≡ v_{y}[y ← (λx.Ax)].

A program e in Λ_{c} evaluates to the value v, eval_{d}(e) ≡ v, if and only if

• e ⟼_{c}^{∗} v, or

• e ⟼_{c}^{∗} Ce′ ⟶_{d} C(λk.e′(λx.A^{†}(k x))) ⟼_{idem}^{∗} C(λk.kv_{y}[y ← (λx.A^{†}(k x))]), or

• e ⟼_{c}^{∗} Ce′ ⟶_{d} C(λk.e′(λx.A^{†}(k x))) ⟼_{idem}^{∗} C(λk.v_{y}[y ← (λx.A^{†}(k x))]).

Note: Once again we tag the first halt continuation in the above definition to distinguish its occurrences in the last term of the reduction.

Based on the above lemmas, it is easy to prove that the two evaluation functions, eval_{c} and eval_{d}, are equivalent.

Theorem 3.9 For e ∈ Λ_{c}, eval_{c}(e) ≡ eval_{d}(e).

Proof. By Lemmas 3.5 and 3.7, λ_{v}-C(d) can simulate standard computations. A simple check of their proofs shows that the reduction steps in the new system indeed conform to Definition 3.8. — For the other direction, assume that eval_{d}(e) = v. Then, either e ⟼_{c}^{∗} e′, in which case the conclusion is obviously true. Or,

e ⟼_{c}^{∗} Ce′ ⟶_{d} C(λk.e′(λx.A^{†}(k x))) ⟼_{idem}^{∗} C(λk.kv_{y}[y ← (λx.A^{†}(k x))])

or

e ⟼_{c}^{∗} Ce′ ⟶_{d} C(λk.e′(λx.A^{†}(k x))) ⟼_{idem}^{∗} C(λk.v_{y}[y ← (λx.A^{†}(k x))])

for an appropriate v_{y}. It is easy to see that in both cases,

e ⟼_{c}^{∗} Ce′ ⟼^{▷}_{c} e′(λx.A^{†}x) ⟼^{▷}_{c}^{∗} v_{y}[y ← (λx.A^{†}x)].

Hence, e ⟼^{▷}_{c}^{∗} v and eval_{c}(e) = v as desired. □

More importantly, we can show that the theory λ_{v}-C(d) can also prove all safe equations in the old theory of control. To establish the claim, we need a lemma for each direction. The safeness of the new proof rules can be established by straightforward calculations.

Lemma 3.10 λ_{v}-C-safe ⊢ C_{idem}, C_{top}.

Proof. The safeness of C_{idem} follows from a simple calculation. Let E be an arbitrary evaluation context. Then,

λ_{v}-C^{▷} ⊢ E[C(λk.Ce)] = (λk.Ce)K  for some term K determined by E
= Ce[k ← K]
= (e[k ← K])(λx.Ax)
= (λk.e(λx.Ax))K
= E[C(λk.e(λx.Ax))].

Verification of the safeness of C_{top} is slightly more complicated:

λ_{v}-C^{▷} ⊢ E[Ce] = eK  for some term K determined by E
= e(λx.A(Kx))  (†)
= (λk.e(λx.A(kx)))K
= E[C(λk.e(λx.A(kx)))].

Since the continuation K is an abstraction of the form λx.Ae, the step (†) is a consequence of the following safe equality:

λ_{v}-C^{▷} ⊢ (λx.A(Kx)) = (λx.A(Ae)) = (λx.Ae) = K.

The equation A(Ae) = Ae follows from the safeness of C_{idem}. □

Every safe equation is also an equation in the new theory λ_{v}-C(d).

Lemma 3.11 If λ_{v}-C-safe ⊢ e = e′, then λ_{v}-C(d) ⊢ e = e′.

Proof. The proof requires several lemmas about the shape of proofs for safe equations. Since it only contributes insight into the old theory, the proof is explained in the appendix. □

The two preceding lemmas show that adding the two axioms C_{idem} and C_{top} to the theory λ_{v}-C(c) provides an axiomatic characterization of the theory of safe equations.

Theorem 3.12 (Safeness) λ_{v}-C(d) ⊢ e_{1} = e_{2} iff λ_{v}-C-safe ⊢ e_{1} = e_{2}

Proof. The theorem follows from Lemmas 3.10 and 3.11. □

An immediate consequence of this theorem is that all equations in the revised theory of control are operationally sound. In other words, two equal expressions are indistinguishable via eval_{d} with respect to all Λ_{C}-contexts (in the sense of Definition 2.7).

Corollary 3.13 If λ_{v}-C(d) ⊢ e_{1} = e_{2} then e_{1} ≃_{c} e_{2}.

As to the classical properties of the new reduction d, we can show that it is Church-Rosser, which provides an alternative proof of λ_{v}-C(d)’s soundness. The Church-Rosser property moreover shows that λ_{v}-C(d) (and, by the proceeding theorem, λ_{v}-C-safe) is a conservative extension of λ_{v}.

Theorem 3.14 (Consistency) The notion of reduction d is Church-Rosser. If e ⟶ ⟶_{d} e_{1} and e ⟶ ⟶_{d} e_{2}, then there is e′ such that e_{1} ⟶ ⟶_{d} e′ and e_{2} ⟶ ⟶_{d} e′.

Proof. ^{2} The proof requires some generalizations of standard techniques. First, we define an alternative set of reduction rules:

2We gratefully acknowledge Erik Crank’s help with this proof.

fa ⟶ δ(f, a)  (δ)
(λx.e)v ⟶ e[x ← v]  (β_{v})
E^{s}[C(λm.e)] ⟶ C(λk.e[m ← (λx.A(k E^{s}[x])))])  (C′_{lift})
C(λk.(C(λm.e))) ⟶ C(λk.e[m ← (λx.Ax)])  (C′_{idem})
C(λm.e) ⟶ C(λk.e[m ← (λx.A(kx))])  (C′_{top})
C e ⟶ C(λk.e (λx.A(k x)))  (C_{top})

We refer to the new set of reductions as d′. It is easy to show that d and d′ are equivalent reduction relations, i.e., ⟶ ⟶_{d} ⊢ d′ and ⟶ ⟶_{d′} ⊢ d. Second, we show in several steps that the new system is Church-Rosser. The proof for

c′ = δ ∪ β ∪ C′_{lift}

is a simple adaptation of the Church-Rosser proof for c [9]. It is also straightforward to prove that C′_{idem}, C_{top} and C′_{top} each directly satisfy the diamond property, and that they are therefore Church-Rosser. Next we combine the relations and use the Hindley-Rossen method [2:64–66] for proving the Church-Rosser property of the larger relations. This is straightforward for the union of c′ and C′_{idem}, of β_{v} and C′_{top}, and of β_{v} ∪ C′_{top} and C_{top}. The final step requires us to show that the reductions based on c′ ∪ C′_{idem} and C_{top} ∪ C′_{top} commute. For this we use Barendregt’s commutation lemma [2:65] for the transitive closure of relations and apply it to c′ ∪ C′_{idem} and a parallel one-step reduction relation based on C_{top} ∪ C′_{top}. Based on this, it is easy to show that the reductions based on c′ ∪ C′_{idem} and β_{v} ∪ C_{top} ∪ C′_{top} commute. Hence, the union, which is the reduction based on d′ is Church-Rosser because both sub-relations are Church-Rosser. Since d and d′ are equivalent as reductions, d is also Church-Rosser. □

The new theory of control also has standard reduction sequences, albeit non-traditional ones. To allow both C_{top} and other d-reductions in standard reduction sequences, we must extend the set of evaluation contexts to a set of d-evaluation contexts such that c standard reduction steps can take place after a C-application reaches the top of the entire term. The rest of the definition is conventional.

Definition 3.15. (d-Standard Reduction Relation; d-Standard Reduction Sequences) Let the set of d-evaluation contexts (E^{d}) be defined as follows:

E^{d} ::= E | C(λk.E).

The standard reduction relation maps e to e′, e ⟼_{d} e′, if there is a d-standard evaluation context E^{d} such that e ≡ E^{d}[p], e′ ≡ E^{d}[q] for some (p, q) ∈ d.

By adding the following clause to the definition of standard reduction sequences of the λ_{v}-calculus (Definition 2.4), we get the set of standard reduction sequences for λ_{v}-C(d):

• If e_{1},…, e_{n} is a standard reduction sequence, then so is C e_{1},…, C e_{n}.

Clearly, the standard reduction for d generalizes the standard reduction for v but is a relation instead of a function. The reduction theory based on d satisfies the same standardization theorem as conventional λ-calculi.

Theorem 3.16 (Standardization) e ⟶ ⟶_{d} e′ if and only if there is a standard reduction sequence e,…, e′.

Proof. The proof is an adaptation of Plotkin’s corresponding proof. □

Finally, we can show that the evaluation function is again determined by the transitive closure of the standard reduction relation based on d. Since the latter determines a relation but not a function, the statement of the theorem takes on a slightly peculiar form.

Theorem 3.17 (Evaluation) eval_{d} ⊆ {(e, v) | e ⟼_{d}^{∗} v, or e ⟼_{d}^{∗} C(λk.kv′), or e ⟼_{d}^{∗} C(λk.v′), where v ≡ v′[y ← (λx.Ax)]}

Proof. The standard reduction relation obviously extends the relations ⟼_{c} and ⟼_{idem} from Definition 3.8. □

With this last theorem, we have explored all the conventional aspects of the connection between programming languages and calculi.

3.3 Extensions of the equational theory

It is not immediately obvious from the preceding discussion why the reduction C_{lift} must be restricted to capturing only singular evaluation contexts. Combined with C_{top}, which effectively captures empty evaluation contexts, the two relations serve to capture arbitrary evaluation contexts. Consequently, the following generalization of C_{lift} would seem to be a natural unification of C_{lift} and C_{top}:

E[C e] ⟶ C(λk.e (λx.A (k E[x]))).  (C_{E})

This rule captures an arbitrary evaluation context in a single step and applies the subterm of the C-application to an appropriate continuation.

The notion of reduction C_{E} subsumes C_{lift} and C_{top} as sub-relations, but the inverse is not true. Consider the term u(v (C e)). Two uses of C_{lift} yield the term

C(λk.e (λx.A ((λy.A (k (u y)))(v x)))),

but a single application of C_{E} with E ≡ u (v [ ]) produces

C(λk.e (λx.A (k (u (v x))))).

Both terms are in normal form and it is thus impossible to prove their equivalence in either λ_{v}-C(d) or λ_{v}-C(d) modified with C_{E}. In short, although C_{E} adds equational power to the calculus, it destroys the Church-Rosser property.

A second extension of the theory λ_{v}-C(d) is based on the observation that the safe theory cannot simulate the evaluation in a perfect manner. In λ_{v}-C(d), there are three different types of answers. First, an evaluation may simply yield a value. Second, an evaluation may abort some part of a computation and produce the answer (Cλk.v) (with v possibly containing k), which basically is an exceptional answer. Finally, the answer may have the shape (Cλk.kv). In this case, the program discovered the answer at some point in the evaluation and used a continuation to escape from the rest of the evaluation. If the answer does not contain any references to the captured continuation, it is uninteresting from an observational perspective that the program used a continuation for escaping from the evaluation process.

We could avoid the third kind of answer for an evaluation in λ_{v}-C(d) by introducing an additional reduction that eliminates C-applications when they have become superfluous:

C(λk.k e) ⟶ e if k ∉ FV (e)  (C_{elim})

Unfortunately d ∪ C_{elim} is not Church-Rosser. A counterexample is the C_{elim}-redex itself, which is also a C_{top}-redex. Whereas a C_{elim}-step yields e, a reduction with C_{top} followed by a β_{v}-step leads to Cλk.((λx.A (k x)) e). Since e does not necessarily have a value, we cannot continue the reduction as necessary.

We leave unsolved the problem of finding an extended theory that includes C_{E} or C_{elim} and still satisfies the classical properties of reduction theories.

4 Theories of state

The extension of the λ_{v}-calculus to a theory of procedural abstraction and assignment requires two new syntactic constructs for the underlying term language. First, there is a need for assignable variables—also called state variables—that denote different values at different times. To distinguish the set of assignable variables from the set of binding variables of the simple λ_{v}-calculus, we rename the latter set Vars_{λ} and refer to the former as Vars_{σ}, annotating elements according to their set-membership: x_{λ} ∈ Vars_{λ} and x_{σ} ∈ Vars_{σ}. Since assignable variables do not denote fixed values, we do not use them as values.

Second, the extended language needs a construct for altering the value, or state, of an assignable variable. For this purpose we use the σ-capability, which is a new form of value, (σx_{σ}.e). A σ-capability is similar to a λ-abstraction, but instead of binding a variable in some expression, it represents the right to assign the variable a new value. Upon invocation, it globally alters the value of its variable and then continues with the evaluation of its subexpression or body. We refer to the extended language as Λ_{σ}.

The notions of substitution, contexts and evaluation contexts are adapted appropriately. The latter definition has the same shape as in the λ_{v}- and the λ_{v}-C-calculus framework, but denotes a subset of contexts over Λ_{σ}.

In the following subsection, we introduce the calculus of procedural abstraction and state [8]. Like the original calculus of control, the state calculus requires two kinds of term relations and, moreover, relies on further extensions of the language Λ_{σ}. We show in the second subsection that both program-level term relations as well as additional language extensions are superfluous. In addition, our new theory of state is a proper extension of the existing one.

4.1 A syntactic theory of state

According to β_{v}, the application of a procedural abstraction to an argument value is equivalent to the evaluation of the procedure body with all occurrences of the procedure parameter replaced by the argument. Given this, it is reasonable to expect that a reduction relation for procedures with assignable parameters replaces the assignable parameter with something that corresponds to the argument value. The traditional solution is to maintain an additional function that maps a parameter name to a value: a store. In our earlier report [8], we demonstrated that the store and its management can be incorporated into the term structure of the program. The key is to keep track of the substituted values via a unique label that is attached to the value before substitution. Based on this labeling scheme, an assignment can be simulated by replacing all values that are tagged with the same label by a different labeled value. The use of the value of an assignable variable requires stripping off the label of the labeled value. The deallocation (or garbage collection) of unusable storage happens automatically.

A complicating fact for the definition of the extended term language is the potential for circular (self-referential) values. For example, the expression (λx.(σx.x)(λy.x))0 evaluates to a recursive function that returns itself upon application. To achieve canonicity in the representation of such values, we add labeled bullets of the shape •^{x} for all labels x. For convenience, we add σ-capabilities with labeled bullets in the variable position (σ •^{x} .e), which represent the result of substituting labeled values for free variables.

Following these preliminary remarks, we define the extension of Λ_{σ} to Λ_{S} with the following abstract syntax:

e ::= v | (ee) | x_{σ} | v^{x} | •^{x}
v ::= c | x_{λ} | (λx_{λ}.e) | (λx_{σ}.e) | (σx_{σ}.e) | (σ •^{x} .e)

The set of labels is the set of assignable variables (used without subscript). When the distinction between assignable and binding variables is irrelevant or deducible from context, we omit the subscripts λ and σ from variables. As indicated above, the substitution of free variables in terms is adapted mutatis mutandis with one exception: (σx.e)[x ← v^{l}] = (σ •^{l} .e[x ← v^{l}]).

Since the labeling strategy is a textual representation of a store, we need to ensure that programs describe consistent stores. For example, every label should be attached to only one value and labeled bullets should be used only to indicate self-references; typical terms that violate these conditions are (λx.1)^{y}(λx.0)^{y} and •^{l}. To eliminate such terms without a corresponding store configuration, we impose three context-sensitive conditions on the term language and use the resulting language as the basis of the calculus:

(C1) an x-labeled bullet (•^{x}) can only occur as a sub-term of an x-labeled value or in the variable-position of a σ-capability, and an x-labeled value must not contain x-labeled values, only x-labeled bullets;

(C2) the bound variable of a λ-abstraction must not occur as a sub-term in a labeled value;

(C3) the labeling of the two subexpressions in an application must be consistent: if v^{x} is a subterm of e and u^{x} is a subterm of e′ where (e e′) is an application, then v and u must be identical after replacing labeled values in them by the labels.

Equipped with the notion of labeled terms, we introduce labeled-value substitution, e[•^{x} ← v^{x}], which replaces all x-labeled values in an expression e by v^{x} such that the resulting expression respects the above conditions. This may involve replacing labeled subvalues by labeled bullets in v.

Next, we can turn to the question of how to simulate the execution of a Λ_{σ} program through reductions of Λ_{S}-terms. For an example, we consider the application of an abstraction with an assignable parameter to a value. We would like to model this effect with a substitution of the parameter by a labeled value. Since the label must be unique for every reduction of such an application, it is impossible to perform several reductions in parallel in different parts of the term.

The coordination of the effects of labeled-value substitutions becomes possible by ensuring that only one such contraction is applicable. Since the only unique point in a term is the root, the calculus again coordinates imperative effects of transition steps by splitting the set of term relations into a set of simple notions of reduction and computation rules. The reductions lift a redex to the top of the program where the computation rules perform the appropriate action. There are three kinds of redexes that require unique actions:

1. the application of a procedural abstraction with an assignable variable to a value, (λx_{σ}.e)v;

2. the application of a σ-capability to a value, (σ •^{x} .e)v, which must proceed with the evaluation of the body after replacing all occurrences of u^{x} with v^{x} in the entire program; and

3. the use of a labeled value, v^{x}, which produces the value v[•^{x} ← v^{x}].

According to the above reasoning, such redexes must be lifted to the top of the program just before they are evaluated. Consequently, the reductions must lift the redexes out of evaluation contexts, and, after applying the appropriate computation rule, the evaluation must continue with the expression in the hole of the original evaluation context. Putting all of this together, we introduce the following notions of reductions where the meta-variables X ranges over assignable variables, labeled values and labeled bullets (depending on context):

\begin{matrix}E[((λx_{σ}.e)v)] & ⟶ & (λx_{σ}.E[e])v & (β_{E}) \\ E[((σX.e)v)] & ⟶ & (σX.E[e])v & (σ_{E}) \\ E[X] & ⟶ & (λv.E[v])X & (D_{E}) \end{matrix}

In accord with the variable assumptions in Section 2, we assume in these equations that variables are renamed as necessary to avoid conflicts.

Once redexes reach the top of the program, the appropriate action must take place. For the simulation of these in a term rewriting system, we define the following computation rules:

\begin{matrix}(λx_{σ}.e)v & ▷ & e[x_{σ} ← v^{y}] where y ∉ FV (e, v) & (β_{T}) \\ (σ •^{x} .e)v & ▷ & e[•^{x} ← v^{x}] & (σ_{T}) \\ (uv^{x}) & ▷ & u(v[•^{x} ← v^{x}]) & (D_{T}) \end{matrix}

Notice that (σx.e)v is a redex for the reduction relations but not for the computation relations: in Λ_{σ} assignments can only be made to bound variables (which are replaced by labeled variables in time).

We define the calculus of state in the same way as the calculus of control. The basic notion of reduction is

s = v ∪ β_{E} ∪ σ_{E} ∪ D_{E}.

When terms are equal according to s, e =_{s} e′, we write λ_{v}-S(s) ⊢ e = e′. As usual, ⟶_{s} and ⟶ ⟶_{s} denote the one-step reduction and its transitive closure. The computation relation is defined by:

▷_{s} = ⟶ ⟶_{s} ∪ β_{T} ∪ σ_{T} ∪ D_{T} .

The relation =^{▷}_{s} is the smallest equivalence relation generated by the computation relation ▷_{s}. We denote equivalences in this theory by λ_{v}-S^{▷} ⊢ e = e′.

The syntactic theory of state satisfies the same variants of the classical properties as the syntactic theory of control. Its sub-theory based on the relation s is Church-Rosser and the computation relation satisfies the diamond property. There are standard reduction sequences for the reduction relation and standard computation sequences for the computation relation. As above, we denote the standard reduction function with ⟼^{▷}_{s}. Most importantly, a subset of the standard computation mapping defines an evaluation function.

Definition 4.1. (s-Standard Computation Function) The standard computation function maps a program e to a program e′, e ⟼^{▷}_{s} e′, if e standard reduces to e′ or if e computes to

e′: ⟼^{▷}_{s} = ⟼_{s} ∪ β_{T} ∪ σ_{T} ∪ D_{T}.

Now the evaluation function on Λ_{σ} (and Λ_{S}), eval_{s}, can again be defined as the transitive closure of the standard computation relation:

eval_{s}(e) = v if e ⟼^{▷}_{s}^{∗} v.

Mutatis mutandis, this definition induces an operational equivalence relation for Λ_{σ} (≃_{σ}) (along the lines of Definition 2.7). Most importantly, we can prove that equations between Λ_{σ} terms in the calculus are safe and imply operational equivalence.

Theorem 4.2 ([8]) Let e and e′ be in Λ_{σ}. If λ_{v}-S^{▷} ⊢ e = e′ then e ≃_{σ} e′.

Unfortunately, the theory λ_{v}-S^{▷} is not compatible with respect to equations over Λ_{σ} terms. For example,

λ_{v}-S^{▷} ⊢ (λx.(σx.2)1)0 = 2,

yet,

λ_{v}-S^{▷} ⊬ λy.(λx.(σx.2)1)0 = λy.2.

In the second equation, the top-level steps that are crucial for evaluating assignments can no longer be performed because the expressions are embedded inside of λ-abstractions. We could solve this problem by introducing an extended theory of safe equations as in the old theory of control, but fortunately, there is a better solution for this problem.

4.2 The revised syntactic theory of state

The crucial insight that leads to an improved theory of state originates from a simple observation about the context-sensitive restrictions of the language Λ_{S}. The motivation for the restrictions is the existence of terms in the unconstrained language that do not represent an intermediate consistent store in the evaluation of a Λ_{σ}-term. The contextsensitive restrictions eliminate such terms.

Lemma 4.3 For every term e ∈ Λ_{S} there is a term e′ ∈ Λ_{σ} such that e′ ▷_{s}^{∗} e.

Proof. By the context-sensitive restrictions on Λ_{S}, for every term e ∈ Λ_{S} with labels x_{1},…, x_{n}, there is a term e′′ ∈ Λ_{σ} with free assignable variables x_{1},…, x_{n} and values u_{1},…, u_{n} in Λ_{σ} such that

e ≡ e′′… [x_{i} ← (λx.x)^{x_{i}}] … [•^{x_{i}} ← (u_{i}… [x_{i} ← (λx.x)^{x_{i}}] …)^{x_{i}}] …

First, for every label x_{i} in e, there is a unique value u_{i} that corresponds to the collection of x_{i}-labeled values. By condition (C3), we can construct this value by replacing all labeled values with their labels in an arbitrary x-labeled value (not a bullet!). This algorithm produces the values u_{1} through u_{n}. Second, we can also obtain e′′ by replacing all occurrences of a labeled value with its label. By construction, the terms e′′, u_{1},…, u_{n} satisfy the above condition. We can now take

e′ ≡ (λx_{1} … x_{n}.(σx_{1} … x_{n}.e′′)u_{1} … u_{n})(λx.x) … (λx.x),

which proves the proposition. □

In order to simplify the presentation of terms like e′ in the preceding lemma, we introduce a simplified version of Landin’s [11] letrec-abbreviation: the ρ-application.^{3} A ρ-application is a combination of a finite function from assignable variables to values, represented as a set θ = {(x_{1}, v_{1}),…, (x_{n}, v_{n})}, and an expression e; it expands according to the construction in the lemma:

ρ{(x_{1}, u_{1}),…, (x_{n}, u_{n})}.e ≡^{df} (λx_{1} … x_{n}.(σx_{1} … x_{n}.e)u_{1} … u_{n})(λx.x) … (λx.x).

The set notation is justified since all expansions corresponding to some linear arrangement of the set clearly reduce to the same term in λ_{v}-S^{▷}. When we write ρθ ∪ θ′.e, we assume that θ ∪ θ′ is a finite function. Finally, we define ρ∅.e ≡ e. We use Dom(θ) to denote the set of defined variables, {x_{1},…, x_{n}}, in the function θ.

It also follows from the above Lemma that every theorem e_{1} = e_{2} in λ_{v}-S^{▷} for e_{1}, e_{2} ∈ Λ_{S} implies the existence of a theorem

ρθ_{1}.e′_{1} = ρθ_{2}.e′_{2}

3Recently, Abadi et al. [1] proposed and studied a variant of the λ-calculus that incorporates explicit substitutions. Our ρ-applications correspond to their closures: in the notation of Abadi et al. ρθ.e would be the term e[θ] for a non-recursive θ. In other words, our ρ-applications generalize their notion of closure to the more common notion of Scheme- and ML-like closures whose lexical variables may be bound to recursive values.

for some ρθ_{1}.e′_{1}, ρθ_{2}.e′_{2} ∈ Λ_{σ}. This holds, in particular, for the computation rules, which we would like to eliminate. Assuming that no labeled value gets lost during a transition, the reformulation of the top-level relations yields the following set of term relations:

\begin{matrix}ρθ.((λx_{σ}.e)v) & ⟶ & ρθ ∪ \{(x, v)\}.e \\ ρθ ∪ \{(x, v)\}.(ux) & ⟶ & ρθ ∪ \{(x, v)\}.(uv) \\ ρθ ∪ \{(x, u)\}.((σx.e)v) & ⟶ & ρθ ∪ \{(x, v)\}.e \end{matrix}

The first rule says that a β_{T} -transition creates a new entry in the ρ-application. The second rule specifies that the use of an assignable variable corresponds to a lookup of the variable in the ρ-application-set. And finally, the assignment is a modification of one pair in the set.

In short, the set of the (global) ρ-application acts like a store, and the translation of the computation rules have the appropriate effects on the finite store. More importantly, these rules are completely independent of the context in which they occur. They do not rely on the uniqueness of new variables, have no effect on the context, and the lookup is relative to the closest (part of the) store in the term. Hence, there is no further need for coordinating these rules, and we may as well take these relations as notions of reduction.

Unfortunately, the above rules are not quite strong enough to replace the computation rules in the preceding subsection. The assumption that a transition does not loose labeled values is too strong. If, for example, a bound assignable variable does not occur in the procedure body, the corresponding instance of β_{T} would translate as

ρθ.((λx_{σ}.e)v) ⟶ ρθ.e,

or even

ρθ.((λx_{σ}.e)v) ⟶ ρθ′.e, θ′ ⊂ θ

if v contains the last reference to some other assignable variables. In general, the right hand side of the new reductions may contain variables in the store of the ρ-application that are no longer relevant to the evaluation of the body. These variables and their associated values are garbage and can be discarded. Whereas garbage collection is automatic in λ_{v}-S^{▷}, we need to introduce an explicit garbage collection rule for the new system:

ρθ_{0} ∪ θ_{1}.e ⟶ ρθ_{1}.e if θ_{0} ≠ ∅ and Dom(θ_{0}) ∩ FV (ρθ_{1}.e) = ∅.  (gc)

We have summarized the revised theory of state in Figure 2. The rules in the figure slightly differ from the rules developed above. In order to reduce the number of reductions, we have merged the λ_{E}-, σ_{E}- and D_{E}-rules with the replacements for the computation rules. This also requires a new term relation, ρ_{∪}, for merging two ρ-applications, which would otherwise be the effect of the lifting rules. The basic reduction relation for the new calculus is

t = v ∪ β_{σ} ∪ D ∪ σ ∪ gc ∪ ρ_{∪}.

The new theory is referred to as λ_{v}-S(t). With Lemma 4.3 and the garbage collection rule, we can show that the new set of rules is a complete replacement for the computation rules.

Lemma 4.4 Let e_{1}, e_{2} ∈ Λ_{S} and let ρθ_{1}.e′_{1}, ρθ_{2}.e′_{2} ∈ Λ_{σ} be their counterparts according to Lemma 4.3. If λ_{v}-S^{▷} ⊢ e_{1} ▷_{s} e_{2} then λ_{v}-S(t), β_{E}, D_{E}, σ_{E} ⊢ ρθ_{1}.e′_{1} ⟶ ⟶ ρθ_{2}.e′_{2}.

fa ⟶ δ(f, a)  (δ)
(λx_{λ}.e)v ⟶ e[x_{λ} ← v]  (β_{v})
(λx_{σ}.e)v ⟶ ρ{(x_{σ}, v)}.e  (β_{σ})
ρθ ∪ {(x, v)}.E[x] ⟶ ρθ ∪ {(x, v)}.E[v]  (D)
ρθ ∪ {(x, u)}.E[(σx.e)v] ⟶ ρθ ∪ {(x, v)}.E[e]  (σ)
ρθ_{0} ∪ θ_{1}.e ⟶ ρθ_{1}.e if θ_{0} ≠ ∅ and Dom(θ_{0}) ∩ FV (ρθ_{1}.e) = ∅  (gc)
ρθ.E[ρθ′.e] ⟶ ρθ ∪ θ′.E[e] if θ′ ≠ ∅ and ρθ.E ≠ [ ]  (ρ_{∪})

Figure 2: The revised syntactic theory of state

Proof. The proof relies on two facts about the construction in Lemma 4.3:

1. The algorithm for converting e to ρθ.e′ does not alter the structure of the term e except for replacing labeled values by labels. In particular, values remain values and non-values remain non-values.

2. The labeled values in e that are moved into the store of the program ρθ.e′ preserve their structure in the same way.

As a consequence, a redex in e_{1} not inside of a labeled value becomes a redex at the homologous position in e′_{1}. More specifically, s-redexes becomes s-redexes and β_{T} -, σ_{T} -, and D_{T} -redexes become instances of β_{σ}-, σ-, and D-redexes, respectively. Similarly, sredexes inside of labeled values in e_{1} become s-redexes inside of the values in the store of ρθ_{1}.e′_{1} that directly contain the redex (a labeled value directly contains a subexpression if there is not a labeled sub-value that contains the subexpression).

Given these preliminaries, it is easy to see that, given a reduction in λ_{v}-S^{▷}, a reduction in λ_{v}-S(t) of the corresponding redex in ρθ_{1}.e′_{1} leads to a term ρθ^{∗}.e′_{2}. Clearly, neither s- nor t-redexes create new free variables but the substitution process associated with s-redexes may eliminate some labels by vacuous substitutions. On the other hand, the corresponding t-redexes will eliminate the corresponding variables. Hence,

ρθ^{∗}.e′_{2} ≡ ρθ_{2} ∪ θ.e′_{2}

such that, by the construction of ρθ_{2}.e′_{2},

Dom(θ) ∩ FV (ρθ_{2}.e′_{2}) = ∅.

This permits an application of the garbage collection rule, gc, and we get

ρθ_{1}.e′_{1} ⟶ ρθ^{∗}.e′_{2} ⟶ ρθ_{2}.e′_{2}. □

The lemma implies that the new theory, extended with the lifting reductions, can prove all the equations on Λ_{σ} that the old theory can prove.

Theorem 4.5 Let e, e′ ∈ Λ_{σ}.

(i) If λ_{v}-S^{▷} ⊢ e = e′ then λ_{v}-S(t), β_{E}, D_{E}, σ_{E} ⊢ e = e′.

(ii) The converse does not hold.

Proof. (i) By the diamond property, λ_{v}-S^{▷} ⊢ e = e′ implies that there is a term e^{∗} such that λ_{v}-S^{▷} ⊢ e ▷_{s}^{∗} e^{∗} and λ_{v}-S^{▷} ⊢ e′ ▷_{s}^{∗} e^{∗}. It follows from Lemma 4.4 that λ_{v}-S(t), β_{E}, σ_{E}, D_{E} ⊢ e ⟶ ⟶ e^{∗} and λ_{v}-S(t), β_{E}, σ_{E}, D_{E} ⊢ e′ ⟶ ⟶ e^{∗}. Therefore, λ_{v}-S(t), β_{E}, D_{E}, σ_{E} ⊢ e = e′.

(ii) Here is a simple proof in λ_{v}-S(t):

λ_{v}-S(t) ⊢ λy.(λx.(σx.2)1)0 = λy.ρ{(x, 0)}.(σx.2)1 = λy.ρ{(x, 1)}.2 = λy.2

As explained at the end of the previous subsection, the resulting theorem is not provable in the old theory. □

A second important consequence of Lemma 4.4 is that the reduction theory based on t alone can simulate the evaluation of Λ_{σ}-programs.

Lemma 4.6 Let e ∈ Λ_{σ}. If eval_{s}(e) = v for some value v ∈ Λ_{S} then e ⟶ ⟶_{t} ρθ.v′ where ρθ.v′ ∈ Λ_{σ} is the counterpart of v according to Lemma 4.3.

Proof. If eval_{s}(e) = v for some value v ∈ Λ_{S}, then e ⟼^{▷}_{s}^{∗} v. In such a series of standard computation steps, subsequences of standard reduction steps according to β_{E}, σ_{E}, and D_{E} are always followed by standard computation steps according to β_{T}, σ_{T}, and D_{T}, respectively; the latter always precedes a β_{v} step, which puts the de-labeled value into the original evaluation context. In other words, β_{E}, σ_{E}, and D_{E} in standard computations only occur in clusters that, by Church-Rosser and diamond property, are equivalent to the following three cases:

1. E[(λx.e)v] ⟼_{s} (λx.E[e])v ▷_{s} E[e[x ← v^{l}]]

2. E[v^{l}] ⟼_{s} (λx.E[x])v^{l} ▷_{s} (λx.E[x])v[•^{l} ← v^{l}] ⟼_{s} E[v[•^{l} ← v^{l}]]

3. E[(σx.e)v] ⟼_{s} (σx.E[e])v ▷_{s} E[e][•^{l} ← v^{l}]

Translating these kinds of sequences into the new calculus according to Lemma 4.4, merges them as β_{σ}/ρ_{∪}, D, and σ steps:

1. ρθ.E[(λx.e)v] ⟶_{t} ρθ.E[ρ{(x, v)}.e] ⟶_{t} ρθ ∪ {(x, v)}.E[e]

2. ρθ.E[l] ⟶_{t} ρθ.E[θ(l)]

3. ρθ ∪ {(x, u)}.E[(σx.e)v] ⟶_{t} ρθ ∪ {(x, v)}.E[e]

In short, the translation incorporates preliminary lifting reductions into the simulated toplevel steps. But then the derivation in the extended theory no longer uses any lifting steps, i.e., λ_{v}-S(t) ⊢ e ⟶ ⟶ ρθ.v′. □

Based on this lemma, we can now define an evaluation function using only t reductions. The main idea behind the definition is that programs can maintain a textual representation of the store in the form of a ρ-application at the root of the program.

Definition 4.7. (t-Evaluation) Let e ⟼_{t1} e′ if

1. e ≡ ρθ.M, M ⟼_{v} M′, and e′ ≡ ρθ.M′, or

2. (e, e′) ∈ (σ ∪ D ∪ gc ∪ (ρ_{∪} ∘ β_{σ})), where (ρ_{∪} ∘ β_{σ}) is the composition of β_{σ} and ρ_{∪}, i.e., a β_{σ}-step followed by a ρ_{∪}-step.

A program e in Λ_{σ} evaluates to the answer ρθ.v, eval_{t}(e) ≡ ρθ.v, if e ⟼_{t1}^{∗} ρθ.v and there is no e′ such that ρθ.v ⟼_{t1} e′.

The single-step evaluation relation (⟼_{t1} ) is a proper relation because of its nondeterministic use of garbage collection. On the other hand, by demanding complete garbage collection, eval_{t} becomes a (partial) function on Λ_{σ} programs. Moreover, it is equivalent to the old evaluation function.

Theorem 4.8 Let e, ρθ.v ∈ Λ_{σ}, v′ ∈ Λ_{S}, and assume that ρθ.v′ ⟼^{▷}_{s}^{∗} v. Then, eval_{s}(e) = v′ if and only if eval_{t}(e) = ρθ.v.

Proof. A simple check of Lemma 4.6 shows that the left to right direction is built into Definition 4.7, and that the arguments are invertible. □

Since, unlike in the case of control, the new theory extends the old theory, we cannot prove the soundness of the new theory via the old one. Instead, we must assert some classical properties first.

First, the theory is Church-Rosser.

Theorem 4.9 (Consistency) The notion of reduction t is Church-Rosser. If e ⟶ ⟶_{t} e_{1} and e ⟶ ⟶_{t} e_{2}, then there is e′ such that e_{1} ⟶ ⟶_{t} e′ and e_{2} ⟶ ⟶_{t} e′.

Proof. The classical methods for Church-Rosser proofs for untyped λ-calculi apply. □

Second, we can define a standard reduction relation and a set of standard reduction sequences for λ_{v}-S(t).

Definition 4.10. (t-Standard Reduction Relation; Standard Reduction Sequences) The definition of ⟼_{t} is based on a set of t-standard evaluation contexts, E:

E ::= E | ρθ.E.

The standard reduction relation maps e to e′, e ⟼_{t} e′, if there is a t-standard evaluation context E such that e ≡ E[p], e′ ≡ E[q] for some (p, q) ∈ t.

By adding the following clause to the definition of standard reduction sequences of the λ_{v}-calculus (Definition 2.4), we get the set of standard reduction sequences for λ_{v}-S(t):

• If e_{1},…, e_{n} is a standard reduction sequence, then so is σx.e_{1},…, σx.e_{n}.

Third, the new theory of state satisfies the usual standardization theorem.

Theorem 4.11 (Standardization) e ⟶ ⟶_{t} e′ if and only if there is a standard reduction sequence e,…, e′.

Proof. The proof is an adaptation of Plotkin’s corresponding proof. □

Finally, we are ready to prove that the new theory is sound. We do this in two steps.

Theorem 4.12 (Evaluation) Let e, ρθ.v be in Λ_{σ}.

(i) If eval_{t}(e) = ρθ.v, then e ⟼_{t}^{∗} ρθ.v.

(ii) If e ⟼_{t}^{∗} ρθ.v, then there exists ρθ′.v′ such that eval_{t}(e) = ρθ′.v′.

Proof. (i) The relation ⟼_{t1} is clearly a subset of the standard reduction relation, in which all non-v steps are restricted to the root of the program.

(ii) The relation ⟼_{t} generalizes ⟼_{t1} such that all reductions can be performed inside of a program as well as at its root. Moreover, it disconnects the relation ρ_{∪} ∘ β_{σ} such that ρ_{∪}- and β_{σ}-reductions can be separated. However, it is also easy to see that a sequence of ⟼_{t} steps can be rearranged so that all ρ-applications are merged with the top-level ρ-applications as soon as they occur in an evaluation context. Clearly, such rearranged sequences are still standard reduction sequences, and more importantly, they are also sequences of ⟼_{t1} -steps. The difference between the two answers is that a standard reduction sequence does not assume that all garbage is eliminated whereas the evaluation function insists on this. □

Now, recall that two Λ_{σ} expressions e and e′ are operationally equivalent, e ≃_{σ} e′, if and only if they are indistinguishable relative to all Λ_{σ} program contexts (in the sense of Definition 2.7). The final theorem says that the new calculus is operationally sound in the sense that two expressions are equivalent in the calculus only if they are operationally equivalent.

Theorem 4.13 If λ_{v}-S(t) ⊢ e = e′ then e ≃_{σ} e′.

Proof. Since λ_{v}-S(t) is a conventional calculus, λ_{v}-S(t) ⊢ e = e′ implies λ_{v}-S(t) ⊢ C[e] = C[e′] for all contexts C . Now assume that for some context C , eval_{t}(C[e]) terminates. By the Standardization Theorem 4.11, C[e]⟼_{t}^{∗} ρθ.v and therefore λ_{v}-S(t) ⊢ C[e′] = C[e] = v. By the Consistency Theorem 4.9 and the Evaluation Theorem 4.12, C[e′] ⟼_{t1}^{∗} ρθ′.v′ and therefore eval_{t}(C[e′]) is defined too. By symmetry, C[e] terminates if and only if C[e′] terminates.

For the second condition, assume that eval_{t}(C[e]) = c and eval_{t}(C[e′]) = d for constants c and d. Then, by Lemma 4.6, λ_{v}-S(t) ⊢ C[e] ⟶ ⟶ c and λ_{v}-S(t) ⊢ C[e′] ⟶ ⟶ d. Hence, c = C[e] = C[e′] = d. Again by the Consistency Theorem, c = d, which proves that e ≃_{σ} e′. □

In summary, the new theory of state based on the reduction t is the essential calculus of state. It can evaluate programs (4.8); it is consistent (4.9); it has standard reduction sequences whose standard reduction relation is an evaluation mechanism (4.12); and it is sound (4.13). Finally, it also extends the old theory (4.5).

Note: The nature of variables

From Scheme’s [19, 21] practical point of view, the new theory only contains one disturbing element, namely, the partitioning of the variable set into binding and assignable variables. The reason for this separation is the desire to use variables as values as in λ_{v}. However, in a language with assignments variables no longer stand for one value but for a series of values. Consequently, they should not be considered as values but as expressions that always have a value. By excluding the set of variables from values, the distinction between the two variable sets becomes superfluous and the language becomes Scheme-like:

e ::= x | v | (e e)
v ::= λx.e | σx.e.

A revised calculus only requires a single axiom for parameter-passing, namely, β_{σ}. The only loss of this modified theory is that it is no longer a conservative extension of the original λ_{v}-calculus.

On the other hand, such a revised calculus easily accommodates another reduction that simplifies work with the calculus. In the revised calculus a variable is said to be assignable if it occurs in the variable position of a σ-capability. When a variable in a ρ-set is no longer assignable, the new calculus can replace the variable with its recursive value:

ρθ ∪ {(x, v)}.e ⟶ (ρθ.e)[x ← v[x ← Y(λx.v)]]  (ρ_{Y})

if x is not assignable in e, v, and θ

and where Y ≡^{df} (λfy.(λx.xx)(λx.f(λy.(xx)y))y).

A restricted version of β_{v} can be derived from ρ_{Y}.

5 Unified theories of control and state

The original theories of control and state are completely orthogonal to each other [5]. The sum of the extended notions of reduction yields a theory for a language with facilities for both control and state manipulation; indeed, the shape of the reduction relations as pattern-matching rules stays the same. As a result, the larger theory contains the theories of procedural abstraction, control and state as sub-sets.

In our new framework, a simple merger is insufficient, since a C-application may block variable references and assignments. Thus we must introduce an additional notion of reduction to move C-applications outside of ρ-applications:

ρθ.Ce ⟶ Cρθ.e  (ρC)

Let Λ_{Cσ} stand for the merged language:

e ::= v | (e e) | (C e) | x_{σ}
v ::= b | f | x_{λ} | λx.e | σx.e

Furthermore, let d′ and t′ stand for the extension of the notions of reduction d and t to Λ_{Cσ}. The new theory of control and state is based on the union of these reductions with ρC:

cs = d′ ∪ t′ ∪ ρC.

Most importantly, the new notion of reduction is syntactically consistent.

Theorem 5.1 The extended notion of reduction cs is Church-Rosser.

Proof. All three parts of the relation satisfy the Church-Rosser property. The proof that the union does is a straightforward generalization of the Hindley-Rossen method [2:ch3]. □

As a consequence, the larger theory contains the theories λ_{v}-C(d) and λ_{v}-S(t) as subsets. Evaluation can be defined for the larger theory. A program p evaluates to q in the new theory if and only if p evaluates to a value v in the old theory, where q is of the form v′ or Cλk.v′_{k}, v′_{k} can be converted to v′ by replacing all occurrences of (ku) with u as in Lemma 3.7, and v′ may be constructed from v using the algorithm of Lemma 4.3.

6 Towards a better understanding of imperative languages

The most closely related research on reasoning with continuations and assignments is the work by Mason and Talcott. Over the past few years, they have developed equational theories for a first-order version of Lisp with destructive cell operations [13], for a Λ_{C}- like language on control [22, 23], and, most recently, for a higher-order imperative version of Lisp without control abstractions [14]. For a fragment of first-order destructive Lisp without arithmetic and recursion, they have also shown that it is possible to obtain a complete theory [15].

Mason and Talcott’s equational proof systems are essentially ad hoc approximations to the operational equivalences of the respective languages. They find the axioms of these theories by extracting and generalizing frequently used laws from example correctness proofs of programs. From a high-level perspective, the axioms are related to our notions of reduction, but the two frameworks strongly differ in the details. Mason and Talcott have not yet addressed the questions of how their theories relate to the underlying theory of procedural abstraction and of how the various theories relate to each other.

An early effort in the direction of equational theories for proving the correctness of higher-order imperative programs is due to Demers and Donahue [4]. The focus of their research is Russell, an extension of the higher-order typed λ-calculus with cells and destructive cell operations; their major result is a proof system for Russell with several dozen axioms, quite unlike our reductions or the Mason-Talcott axioms. Besides equational assertions, the theory also has statements for expressing the purity and legality of expressions as well as their imperative effect. There are no formal results on the equational theory nor its relationship to the original λ-calculus.

Neither Mason and Talcott’s research nor the work by Demers and Donahue provides an analysis of the equational theories from the perspective of a reduction theory. Both theories are clearly intended for practical use with a particular programming language and proof system.

The principal motivation for our work is a better understanding of the essence of imperative extensions of higher-order programming languages based on the λ-calculus. Our new theories rely on minimal sets of notions of reduction, which provide a simple operational semantics for the respective languages. The λ_{v}-calculus is the core of all theories; the various theories are conservative extensions of the respective subtheories. In this sense, our operational semantics is modular: the semantics of an extended language is an extension of the semantics for the simpler language. The advantage of this approach is that results on evaluation and proof systems automatically lift to richer languages; the disadvantage is a certain weakness of the proof systems. We believe that recent work by Moggi [17] on the computational λ-calculus—motivated by similar concerns—and our own work are the correct starting point for developing modular proof systems for large, powerful languages.

The development of a good proof system will require the development of an induction principle and other mathematical tools in order to strengthen the power of the system. One possible solution is to work with the underlying operational approximation relation and to axiomatize its use [14]. The more popular direction relies on the ideas of denotational semantics. Currently, however, denotational semantics provides different models for different languages, especially in the realm of the imperative, higher-order language family. It is consequently difficult to relate results on a language to results on its extensions. Our approach to operational semantics should lead to a collection of denotational models for imperative higher-order languages in which a model for an extended language contains the model for the core language as a projection. Such a denotational theory would provide an improved understanding of control and state in programming languages and their relationship to other language facilities.

Acknowledgement Both Udday Reddy and Carolyn Talcott independently suggested to look for simpler, congruent versions of our calculi. Tim Griffin read an early draft of this paper and proposed clarifications of several opaque points in our discussions. Erik Crank came up with large number of counter-examples to the Church-Rosser property of various extensions of our control theory; he also pointed out a flaw in an early draft of the proof for the Soundness Theorem of the new state theory. We also appreciate the referees’s efforts, leading to the elimination of a number of mistakes and a greatly improved presentation of our results.

A Appendix: Proof of Lemma 3.11

Before we can sketch the proof of Lemma 3.11, we need to collect some facts about the general shape of proofs of safe equations. We know from the definition of safeness that if e =^{▷}_{c} e′ is safe then E[e] =^{▷}_{c} E[e′] is a theorem for every evaluation contexts E. Consequently, by the Church-Rosser and the Standardization Theorems, there must be standard computation sequences from E[e] and E[e′] to some term p. The proof of Lemma 3.11 relies on the fact that these two standard computation sequences have certain properties.

Definition A.1. (Standard Computation Sequences) Standard reduction sequences based on the relation c are defined just like standard reduction sequences for the relation d: see Definition 3.15. We extend standard reduction sequences for c to standard computation sequences for the theory λ_{v}-C^{▷} as follows:

1. All standard reduction sequences are standard computation sequences.

2. If e ⟼^{▷}_{c} e_{1} and e_{1},…, e_{n} is a standard computation sequence, then e, e_{1},…, e_{n} is a standard computation sequence.

For the following lemmas, we use the terminology grabbing a continuation, by which we mean a sequence of applications of C_{lift} followed by a top-level transition C_{T}, which creates a new abstraction of the form (λx.Ax) and provides access to an abstraction of the evaluation context E. We represent such a continuation with (A+E). The following lemma provides the justification for this notation by connecting the invocation of the continuation to the reduction of the encoded evaluation context. Again, we label instances of A in order to keep track of continuations.

Lemma A.2 ([9]) ((A + E)v) ⟼^{▷}_{c}^{∗} Au if and only if E[v] ⟶ ⟶_{c} u.

Furthermore, the definition of a standard computation sequence implies that all toplevel transitions in a standard computation sequence are part of the series of standard computation steps at the front-end of the sequence. In particular, if a sequence grabs and invokes a continuation, then there is a standard mapping between the two points.

Lemma A.3 If E[C e] ⟼^{▷}_{c}^{∗} e(A^{†} + E) and e(A^{†} + E),…, A^{†}v is a standard computation sequence (for some value v), then E[C e] ⟼^{▷}_{c}^{∗} A^{†}v.

Proof. Obvious: (A^{†}v) can only get to the root of the program by computation rules. By Definition A.1 such transitions can only take place within the series of standard computation steps at the front-end of the term sequence. □

The two preceding lemmas lead to the first crucial property of the standard computation sequences for safe equations. If both sequences grab a continuation, the continuation is invoked if and only if both sequences invoke it.

Lemma A.4 Let Ce =^{▷}_{c} Ce′ be a safe equation. Let E be an arbitrary evaluation context and let p be such that

E[Ce] ⟼_{c}^{∗} e(A^{†} + E),…, p

and

E[Ce′] ⟼_{c}^{∗} e′(A^{†} + E),…, p

where e(A + E),…, p and e′(A + E),…, p are standard computation sequences. Then, e(A^{†} + E) ⟼^{▷}_{c}^{∗} A^{†}v if and only if e′(A^{†} + E) ⟼^{▷}_{c}^{∗} A^{†}u for some values v and u.

Proof. By Lemma A.3, it suffices to look at the front-end of the standard computation sequence. Thus assume that e invokes the continuation but e′ does not. Since the computation sequences are in standard form, the decision to invoke or not to invoke the continuation does not depend on the evaluation context E. Hence, we may consider a less arbitrary context, say, E ≡ (λx.c)[ ] for some constant c not in e or e′. By Lemma A.3, this implies p ≡ c.

The second derivation sequence, on the other hand, may or may not discard the newly created continuation. If it does not, p must still contain the corresponding new A-applica-tion. On the other hand, if e′ throws away its continuation, p can no longer contain any part of the evaluation context, i.e., the unique constant c. In either case, the second derivation sequence places inconsistent requirements on the term p. This contradiction proves our claim. □

A second property of standard computation sequences for safe equations is that if only one of the derivation sequences grabs the evaluation context, then the common term is an A-application and the continuation is never invoked.

Lemma A.5 Let Ce =^{▷}_{c} e′ be a safe equation. Let E be an arbitrary evaluation context and let p be such that

E[Ce] ⟼_{c}^{∗} e(A^{†} + E),…, p

where e(A^{†} + E),…, p is a standard computation sequence. Moreover, let

E[e′] ⟶ ⟶_{c} p

and let E[e′],…, p be the corresponding standard computation sequence.

Then, p ≡ Aq for some q. Moreover, it is impossible that e(A^{†} + E) invokes the continuation (A^{†} + E), i.e., it is impossible that p ≡ A^{†}q.

Proof. It is easy to see that the evaluation context in this continuation must not occur in p because the second term, e′, cannot construct (A^{†} + E) for arbitrary contexts E. Consequently, the first derivation must eliminate all pieces of E including the labeled continuation (A^{†} + E), and p cannot contain any pieces of the evaluation context. As a result, the second derivation sequence must abort the entire evaluation context E without performing a top-level step. Consequently, the term p is of the shape Aq for some term q. By the above argument that p does not contain a tagged abort application, we also know that p ≢ A^{†}q. □

With Lemmas A.4 and A.5, we can now prove Lemma 3.11.

Lemma 3.11 If λ_{v}-C-safe ⊢ e = e′, then λ_{v}-C(d) ⊢ e = e′.

Proof. The proof is an analysis of the derivations of the equations E[e] =^{▷}_{c} E[e′]. As discussed, there must be two standard computation sequences that start in the two distinct terms and end in a common term:

E[e],…, p and E[e′],…, p.

There are three major cases:

1. Neither standard computation sequence uses top-level rules. Then the standard computation sequences are such that

E[e] ⟶ ⟶_{c} p and E[e′] ⟶ ⟶_{c} p.

Since ⟶ ⟶_{c} ⊂ ⟶ ⟶_{d}, these reductions also hold in d, and λ_{v}-C(d) ⊢ E[e] = E[e′].

2. Both sequences grab the continuation. According to Lemma A.4, we must now distinguish two subcases:

(a) Both sequences invoke the continuation:

E[e] ⟼_{c}^{∗} q(A^{†} + E) ⟼^{▷}_{c}^{∗} E′[(A^{†} + E)v]
⟼^{▷}_{c}^{∗} A^{†}u[y ← (A^{†} + E)]

and

E[e′] ⟼_{c}^{∗} q′(A^{†} + E) ⟼^{▷}_{c}^{∗} E′′[(A^{†} + E)v′]
⟼^{▷}_{c}^{∗} A^{†}u′[y ← (A^{†} + E)].

By Lemmas 3.5 through 3.7, we know that the following holds in λ_{v}-C(d):

E[e] ⟼_{d}^{∗} C(λk.q(A^{†} + k + E))
⟶ ⟶_{d} C(λk.ku[y ← (A^{†} + k + E)])

and

E[e′] ⟼_{d}^{∗} C(λk.q′(A^{†} + k + E))
⟶ ⟶_{d} C(λk.ku′[y ← (A^{†} + k + E)]).

Since u and u′ are values, the rest of the standard computation sequence must be provable in λ_{v}-C(c):

λ_{v}-C(c) ⊢ u[y ← (A^{†} + E)] = u′[y ← (A^{†} + E)]

By this we directly have that

λ_{v}-C(d) ⊢ u[y ← (A^{†} + k + E)] = u′[y ← (A^{†} + k + E)].

But then we also get that

λ_{v}-C(d) ⊢ C(λk.ku[y ← (A^{†} + k + E)]) =
C(λk.ku′[y ← (A^{†} + k + E)])

and hence λ_{v}-C(d) ⊢ E[e] = E[e′].

(b) Neither sequence invokes the continuation. The analysis of case 2a applies again with the exception that the intermediate terms

C(λk.ku[y ← (A^{†} + k + E)])

and

C(λk.ku′[y ← (A^{†} + k + E)])

look like

C(λk.u[y ← (A^{†} + k + E)])

and

C(λk.u′[y ← (A^{†} + k + E)]),

respectively.

3. Finally, it may be the case that one sequence grabs the continuation and the other

does not:

E[e] ⟼_{c}^{∗} q(A^{†} + E),…, p and E[e′] ⟶ ⟶_{c} p.

It follows from Lemma A.5 that p has the shape Ar, that r does not contain the tagged continuation, and that q does not invoke the continuation. Again by Lemmas 3.5 through 3.7

E[e] ⟶ ⟶_{d} C(λk.q(A^{†} + k + E))

and, given that (A^{†} + k + E) does not occur in p,

E[e] ⟶ ⟶_{d} C(λk.q(A^{†} + k + E)) ⟶ ⟶_{d} C(λk.p), k ∉ FV (p).

Since we know from Lemma A.5 that p is of the shape Ar ≡ Cλd.r for some r with d not in r, we can derive the rest with a simple calculation:

λ_{v}-C(d) ⊢ Cλk.p = Cλk.(Cλd.r)
= Cλk.(λd.r)(λx.A(k x))
= Cλk.r
≡ p.

These are all possible cases and now we know that λ_{v}-C(d) ⊢ E[e] = E[e′] for all E. This holds in particular for E ≡ [ ] and therefore λ_{v}-C(d) ⊢ e = e′. □

References

1. Abadi, M., L. Cardelli, P.-L. Curien, and J.-J. Lévy. Explicit substitution. In Proc. 17th ACM Symposium on Principles of Programming Languages, 1990, 31–46.

2. Barendregt, H.P. The Lambda Calculus: Its Syntax and Semantics. Revised Edition. Studies in Logic and the Foundations of Mathematics 103. North-Holland, Amsterdam, 1984.

3. Church, A. Introduction to Mathematical Logic. Princeton University Press, Princeton, New Jersey, 1956.

4. Demers, A. and J. Donahue. Making variables abstract: an equational theory for Russell. In Proc. 10th ACM Symposium on Principles of Programming Languages, 1983, 59–72.

5. Felleisen, M. The Calculi of Lambda-v-CS-Conversion: A Syntactic Theory of Control and State in Imperative Higher-Order Programming Languages. Ph.D. dissertation, Indiana University, 1987.

6. Felleisen, M. The theory and practice of first-class prompts. In Proc. 15th ACM Symposium on Principles of Programming Languages, 1988, 180–190.

7. Felleisen, M. and D.P. Friedman. Control operators, the SECD-machine, and the λ-calculus. In Formal Description of Programming Concepts III , edited by M. Wirsing. Elsevier Science Publishers B.V. (North-Holland), Amsterdam, 1986, 193–217.

8. Felleisen, M. and D.P. Friedman. A syntactic theory of sequential state. Theor. Comput. Sci. 69(3), 1989, 243–287. Preliminary version in: Proc. 14th ACM Symposium on Principles of Programming Languages, 1987, 314-325.

9. Felleisen, M., D.P. Friedman, E. Kohlbecker, and B. Duba. A syntactic theory of sequential control. Theor. Comput. Sci. 52(3), 1987, 205–237. Preliminary version in: Proc. Symposium on Logic in Computer Science, 1986, 131–141.

10. Griffin, T. A formulae-as-types notion of control. In Proc. 17th ACM Symposium on Principles of Programming Languages, 1990, 47–58.

11. Landin, P.J. The next 700 programming languages. Commun. ACM 9(3), 1966, 157–166.

12. Landin, P.J. The mechanical evaluation of expressions. Comput. J. 6(4), 1964, 308– 320.

13. Mason, I.A. Equivalences of first-order Lisp programs. In Proc. Symposium on Logic in Computer Science, 1986, 105–117.

14. Mason, I.A. and C. Talcott. Programming, transforming, and proving with function abstractions and memories. In Proc. International Conference on Automata, Languages and Programming. Springer Lecture Notes in Computer Science, Berlin, 1989, 574-588.

15. Mason, I.A. and C. Talcott. A sound and complete axiomatization of operational equivalence between programs with memory. In Proc. Symposium on Logic in Computer Science, 1989, 284–293.

16. Milner, R., M. Tofte, and R. Harper. The Definition of Standard ML. The MIT Press, Cambridge, Massachusetts and London, England, 1990.

17. Moggi, E. Computational lambda-calculus and monads. In Proc. Symposium on Logic in Computer Science, 1989, 14–23.

18. Plotkin, G.D. Call-by-name, call-by-value, and the λ-calculus. Theor. Comput. Sci. 1, 1975, 125–159.

19. Rees, J. and W. Clinger (Eds.). The revised^{3} report on the algorithmic language Scheme. SIGPLAN Notices 21(12), 1986, 37–79.

20. Steele, G.L., Jr. Common Lisp—The Language. Digital Press, 1984.

21. Sussman, G.J. and G.L. Steele Jr. Scheme: An interpreter for extended lambda calculus. Memo 349, MIT AI Lab, 1975.

22. Talcott, C. Rum: An intensional theory function and control abstractions. In Proc. 1987 Workshop on Foundations of Logic and Functional Programming. Springer Lecture Notes 306, 1988.

23. Talcott, C. The Essence of Rum—A Theory of the Intensional and Extensional Aspects of Lisp-type Computation. Ph.D. dissertation, Stanford University, 1985.