Fixed Points and Extensionality in Typed Functional Programming

Languages

Brian T. Howard Computer Science Department

Stanford University October 19, 1992

Abstract

We consider the interaction of recursion with extensional data types in several typed functional programming languages based on the simply-typed lambda calculus. Our main results concern the relation between the equational proof systems for reasoning about terms and the operational semantics for evaluating programs. We also present several results about the expressivity of the languages, compared according to both the functions and the data types definable in them. The methods used are those of classical lambda calculus and category theory.

The first language discussed is a variant of Scott and Plotkin’s PCF, which adds to the simply-typed lambda calculus products, fixed points of functions, and algebraic data types specified by a signature and a set of equations. PCF is able to express all partial computable functions over the given basic types, but the corresponding reduction system is not confluent if we include the usual surjective pairing rule, which expresses the extensionality of products. Extensionality is necessary in the proof system for establishing many useful isomorphisms between types, but it does not seem to have an intuitive “computational content.” We show that a smaller reduction system without extensional rules is sufficient for computing the result of program execution, and that this smaller system is confluent whenever the algebraic rules are confluent and left-linear. If the algebraic rules are also terminating and left-normal then a leftmost reduction strategy is complete for finding normal forms.

We then consider a pair of languages, λ^{μν} and λ^{⊥ρ}, which support the definition of structured data types through categorical means rather than via multi-sorted algebras. The first language, λ^{μν}, extends the types of the simply-typed lambda calculus with extensional products and sums, and least and greatest fixed points of positive recursive type expressions. By dropping the extensional rules as for PCF, we obtain a confluent and strongly normalizing reduction system, adequate for obtaining results of programs. It is easy to represent many common data types in this language, such as booleans, natural numbers, lists, trees, and (computable) streams, as well as many of the total functions over such structures. Indeed, we may define more functions over the natural numbers than are provably total in Peano arithmetic, hence the language is more expressive than Gödel’s system T. It is no more expressive than the Girard/Reynolds system F in terms of definable functions; however, we are able to define algorithms that are not expressible in F, such as a constant-time predecessor function on the naturals.

The final language, λ^{⊥ρ}, extends λ^{μν} by introducing lifted types, which contain an element ⊥, called “bottom”, signifying that evaluation of a term of such a type may not terminate. Lifted types allow us to find fixed points of mixed-variant recursive type expressions; for example, the solution of X = X → X_{⊥} gives a type for expressions of an eager untyped lambda calculus, while the solution of X = (X → X)_{⊥} is suitable as a type for expressions of a lazy untyped calculus. We again have a confluent operational semantics for the language, although of course it is not strongly normalizing. However, we show that a lazy reduction strategy will find normal forms for terms which have them. We also examine the relations among the three kinds of recursive type in λ^{⊥ρ}, which we refer to as inductive (least), projective (greatest), and retractive (mixed-variant); in the natural cpo model of the language, we give conditions under which the different constructions will coincide.

Acknowledgements

This report is essentially identical to the Ph.D. dissertation I submitted to Stanford University in August, 1992; only minor changes of wording have been made to improve some line breaks. The material in Chapter 2 is a revised and expanded version of a joint paper with John Mitchell which was presented at the 1990 ACM Conference on Lisp and Functional Programming [26]. Among the many people whom I wish to thank for helpful discussions and insightful suggestions are Michael Barr, Val Breazu-Tannen, Kim Bruce, Luca Cardelli, Pierre-Louis Curien, John Greiner, Bob Harper, Furio Honsell, Pat Lincoln, Eugenio Moggi, Andy Pitts, Vaughan Pratt, Andre Scedrov, Rick Statman, Ramesh Viswanathan, Roel de Vrijer, and Phil Wadler. In particular, this work would not have been possible without the guidance and inspiration of my advisor, John Mitchell, and the love, support, and wisdom of my wife, Eleanor.

This material is based upon work supported under a National Science Foundation Graduate Fellowship. Any opinions, findings, conclusions or recommendations expressed in this publication are those of the author and do not necessarily reflect the views of the National Science Foundation.

Contents

Abstract i

Acknowledgements ii

1 Introduction 1

2 Extensionality in PCF with Algebraic Types 3 2.1 Signatures and terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2 Equations and reduction rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.3 Example: natural numbers and booleans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.4 Confluence of the reduction system pcf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.5 Postponement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2.6 The result property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 2.7 Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 2.8 Completeness of leftmost reduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 2.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3 Inductive and Projective Types 21 3.1 Syntax of the language λ^{μν} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 3.2 Equational proof system for λ^{μν} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 3.3 The reduction system λ_{r}^{μν} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.4 Comparison with System T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.5 Comparison with System F . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

4 Retractive Types and Non-termination 44 4.1 Syntax of the language λ^{⊥ρ} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.2 Equational proof system for λ^{⊥ρ} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 4.3 The reduction system λ_{r}^{⊥ρ} . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 4.4 Example: call-by-name and call-by-value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4.5 Comparison of recursive types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

5 Conclusions 62

Bibliography 63

Chapter 1

Introduction

The subject of this thesis is the interaction of recursion with extensionality in typed functional programming languages. The particular languages we will be considering are all extensions of the simply-typed lambda calculus, λ^{τ}, as described for example in Appendix A of Barendregt [1]. The system λ^{τ} itself is not particularly expressive; since every term has a normal form, only terminating functions are definable.^{1} In Chapter 2 we add an explicit fixed point operator on values, while in Chapters 3 and 4 we extend the type system with solutions to recursive type equations; the net effect in either case is that all partial recursive functions over the natural numbers become expressible. By Church’s Thesis this means we can represent any computable function, using an appropriate coding of the function’s domain into the natural numbers.

For real programming applications, of course, we would not be satisfied with a language that required coding everything into natural numbers before execution. Instead we want types whose values have more structure. In Chapter 2 the types which are added are products, whose values are pairs, and algebraic data types, whose values are built up from a user-specified set of constructors. In Chapters 3 and 4 a more unified approach is taken, where the user may define types from products and sums by taking fixed points of type expressions. In both cases we are interested in proving that various types are in some sense equivalent; for example, we would like to be able to show that (A×B)→C and A→(B→C) are isomorphic, since the latter is the type of “curried” versions of the two-argument functions of the former type. To prove such equivalences we need to know that the basic type constructors such as product and function space are extensional, in the sense that the whole of any term of such a type is no greater than the sum of its parts. In the case of product, for example, this is what is usually referred to as a surjective pairing — every element of a product type is equal to the pair composed of the first and second projections of the element. We draw considerable inspiration from category theory in developing the systems in this thesis; in categorical terms, a type constructor is extensional when it is universal, which means that it is unique in a particular way among some class of constructors.

Extensionality causes several problems when naively combined with recursion. In Chapter 2, the problem arises in trying to associate an operational semantics with a given equational description of the language PCF. In the presence of recursively formed terms, a reduction rule based on surjective pairing will cause confluence of the system to fail; that is, there may be two distinct orders in which to perform reductions on a single term which will never be able to produce a common descendent term. Even without recursion, the standard η-reduction rule, which provides extensionality for functions, may cause a failure of confluence through interaction with algebraic rules. We show that this dependence on reduction order is not an essential difficulty, since there is a confluent reduction system without the extensional rules which is able to compute the normal forms of all programs (technically, a program is a term of observable type with no free variables) that have normal forms in the full, non-confluent system. This supplies a theoretical basis for the folkloric belief that the extensional rules do not have any “computational content.” In Chapter 2 we also show that this smaller reduction system remains confluent when combined with any confluent set of linear algebraic rewrite rules, thus the resulting reduction system serves as a computationally adequate operational semantics corresponding to the axiomatic semantics given by the equations (including extensionality) for the language.

1In fact, the only functions definable over the Church numerals are the extended polynomials, which include addition, multiplication, and zero-test, but not exponentiation [49, 52].

The problem considered in Chapters 3 and 4 is that a type system with extensional sum and product types and solutions to all recursive type equations must be inconsistent — all the types will be isomorphic, and all the terms will be equal. The standard solution is to drop the extensionality condition from either sums or products. We prefer to keep extensionality, for the sake of the equational proof system, and instead restrict the type equations which may be solved. A benefit of this approach is that the resulting system, λ^{⊥ρ}, contains a very expressive terminating subsystem (this is the subject of Chapter 3), which permits us to analyze quite finely the possible sources of non-termination in programs; in theory, an optimizing compiler could use this information to perform extensive partial evaluation of a program, with no worry of going into an infinite loop (although this would be unacceptably inefficient if applied naively). Another possible application of this terminating sublanguage is in proving properties of programs, where knowing that a function is total may permit stronger proof techniques. We show that the smaller, strongly normalizing calculus, λ^{μν}, is more expressive than Gödel’s system T, because it is possible to define all the functions that are provably total in Peano arithmetic as well as some that are not.

All the reduction systems we have mentioned so far are non-deterministic. By showing that they are confluent we are able to abstract away considerations of reduction order and examine the properties of an “ideal” implementation. Since the reduction system for λ^{μν} is strongly normalizing, we may choose any deterministic strategy for evaluating programs and be guaranteed of reaching the same results. For PCF and λ^{⊥ρ}, however, the choice of strategy can affect whether reduction will reach a normal form or diverge. We show for both of these languages that a leftmost reduction strategy is normalizing. The result for PCF depends on the form of the algebraic rules; they must be terminating and left-normal, a syntactic condition which intuitively says that a leftmost strategy is normalizing for the algebraic rewrite system alone.

Extensionality in PCF with Algebraic Types

Most systems of lambda calculus have three parts: an equational proof system, a set of reduction rules, and a model theory. These correspond to the standard programming language notions of axiomatic, operational, and denotational semantics. To a first approximation, the connections between axiomatic and operational semantics are straightforward in basic systems such as the simply-typed lambda calculus. The reduction rules may be derived by orienting each equational axiom in a computationally reasonable way and the resulting system is confluent. As a result, the reduction rules serve simultaneously as a useful characterization of equational provability and as a natural model of execution. When we add recursion to simply-typed lambda calculus with cartesian products, this straightforward correspondence breaks down. Since confluence fails [38], the reduction rules do not give a good picture of equational provability. Moreover, upon examining the reduction rules more carefully, many investigators have come to the conclusion that neither η-reduction nor surjective pairing is computationally compelling. In fact, it seems to be a common view that η-reduction and surjective pairing do not have any “computational content.” Therefore, for both technical and intuitive reasons, we are led to define evaluation without these reduction rules.

In this chapter, we study a simply-typed lambda calculus with functions, pairing, fixed-point operators and arbitrary algebraic data types. We will refer to this language as PCF, since it is based on the calculus considered in Plotkin’s seminal paper [43], with pairing and algebraic data types added.^{1} If we include algebraic data types of natural numbers and booleans, as in [43, 50], then it is easy to program any partial recursive function on the natural numbers. With algebraic data types of trees, lists, stacks, and so on, we may write common functional programs in the style of Miranda or Lazy ML, for example [53].

While most sequential implementations of lazy languages are based on a deterministic (typically “leftmost”) evaluation order, there are several reasons to study arbitrary order. One motivation is parallel execution. If the result of evaluation does not rely on evaluation order, then many subexpressions may safely be evaluated in parallel (see [25, 40], for example, for related discussion). Another reason to consider arbitrary evaluation order is to identify desirable properties of a particular implementation. For example, if a set of reduction (or evaluation) rules is confluent, then the result of nondeterministic evaluation is well-defined and we may regard this as the “ideal” implementation. We may then show that a particular evaluation order is satisfactory by comparison with nondeterministic evaluation. We will do this in Section 2.8, where we show that a leftmost reduction strategy is complete for finding normal forms, provided the algebraic rules satisfy certain conditions.

1The language itself seems attributable to Scott, since the basic ideas are presented in the manuscript [50] and Plotkin’s name for the calculus is clearly derived from Scott’s LCF (Logic for Computable Functions).

For any variant of PCF with equationally-axiomatized algebraic data types, there is a traditional and accepted equational proof system. The axioms of this proof system include η-equivalence (extensionality) for functions

(η)_{eq} λx: σ. Mx = M, x not free in M,

and the surjective pairing axiom

(sp)_{eq} ⟨π_{1}P, π_{2}P ⟩ = P,

where π_{1} and π_{2} are the first and second projection functions. These seem essential for proving common facts about functions and pairs. For example, both are needed to establish that currying and uncurrying are inverses (or, equivalently, that types σ→(τ→ρ) and (σ × τ)→ρ are isomorphic). However, neither seems to be used in standard implementations. If we direct these equational axioms from left to right, we obtain evaluation rules, (η) and (sp), that could be used in program execution but which typically do not have any counterpart in practical implementation. One reason surjective pairing is difficult to implement is that it is non-linear: the meta-variable P occurs twice on the left-hand side. In order to apply the reduction, we must therefore test two potentially large subexpressions for syntactic equality. This seems inefficient, in general, and it follows from our results that such a test is unnecessary for evaluation of complete programs.

In addition to the folkloric view that (η) and (sp) are not needed in computation, which we justify in Corollary 2.5.6, there are technical problems with these rules. While pure typed lambda calculus with these rules but without fixed-point operators is confluent [45], the situation is substantially different in the presence of recursion. Even without any algebraic data types, (sp) and recursion cause confluence to fail. This may be demonstrated by adapting Klop’s well-known counterexample^{2} to confluence in the untyped lambda calculus with surjective pairing [38]. Similar reasoning also shows that in a language with recursion, confluence may fail when confluent but non-linear algebraic rules are added. Although not as immediately problematic, (η) also interferes with confluence of algebraic rules. For example, the simple rewrite rule zero x ⟶ 0, combined with (η), is not confluent; the term λx: nat. zero x reduces to both λx: nat. 0 and zero, which are distinct normal forms. Therefore, considering only the technical property of confluence, both (η) and (sp) seem problematic.

Our first major theorem is that, without (η) and (sp), PCF reduction is confluent over any algebraic data types, provided that the algebraic rewrite rules are all linear and confluent when considered apart from PCF. This result, described in Section 2.4, extends a similar theorem of [6] to pairing and fixed-point operators. Our proof technique combines labelled reduction [1] with the method of [6], which relies on strong normalization. In combining lambda calculus with additional reduction rules, our theorem is also similar in spirit to the delta reduction theorem of Mitschke (see [1]), although our result neither subsumes nor is subsumed by his — Mitschke deals with the untyped calculus, so the delta rules may contain arbitrary lambda terms instead of just algebraic terms, but the set of delta rules has to be disjoint, while we only require that the algebraic rules be confluent. Given the apparent suitability of PCF reduction without (η) and (sp), we proceed to study connections between this limited reduction system and the natural equational axioms.

Since we have dropped two equational rules, it is not immediately clear whether the reduction system is computationally adequate. In other words, do we still have “enough” evaluation rules? While there are provably equal expressions, such as λx: nat.zero x and zero, which do not reduce to a common form, we show that this is not the case for “full programs.” In more detail, the programs we execute in practice are closed expressions of basic types such as nat, bool and list, or perhaps products of basic types. We show that for any closed expression M of “observable” type, and possible result N of complete execution, M reduces to N using all reduction rules iff M reduces to N without (η) and (sp). Thus we have not lost anything by dropping these rules. Moreover, and perhaps more importantly, such expressions M and N are provably equal, possibly using (η)_{eq} and (sp)_{eq}, iff M reduces to N by reduction without (η) and (sp). In standard computational terms, this demonstrates the computational adequacy of our operational semantics with respect to the axiomatic semantics (cf. [23]). The first of these theorems follows from a postponement property of (η) and (sp), while the second uses a refinement of the postponement proof. Typing is essential here, since (sp) postponement fails for untyped terms.^{3}

2A slick presentation is given in [1]. However, the exact counterexample given there cannot be typed. Instead, one must consider a version of the counterexample given in Klop’s thesis [28].

Our last connection between axiomatic and operational semantics is soundness of the axioms with respect to computation. In general terms, if we begin with an intuitively appealing axiomatic semantics, then it seems fair to base evaluation on any equational principles which follow from the axioms. However, once we have selected an operational semantics, we must also ask whether this semantics justifies the equational principles we began with. Put simply, are the equational axioms sound statements about the result of program execution? We answer this question (affirmatively) using the standard notion of observational congruence. This is the natural equivalence relation generated by execution of full programs, and as the name implies it is a congruence relation. Briefly, two expressions are observationally congruent iff they are interchangeable in all programs. Put another way, expressions M and N, which may be higher-order functions or other “non-programs,” are observationally congruent iff we may replace any occurrence of M in a full program by N without affecting the result of program execution. In Section 2.6, we show that the axioms (η)_{eq} and (sp)_{eq}, and hence all the equational rules, are sound for observational congruence. This shows that although we have eliminated some equational principles from execution, we have not invalidated our axiomatic semantics. The proof uses postponement of (η) and (sp).

In Section 2.7 we consider an alternate method of avoiding the confluence problems of the extensional rules. By using (η) and (sp) as expansion instead of contraction rules, we obtain a confluent reduction system for PCF. It is an immediate corollary of the confluence theorem for this system that every term which is provably equal to a normal form will reduce to a unique syntactic variant of that normal form known as a long normal form; thus this system is useful for reasoning about equality of arbitrary terms with normal forms. For reasoning about equality of programs, of course, the computational adequacy theorem shows that the expansion rules add nothing.

Finally, we show that, under certain conditions on the algebraic rules, a leftmost reduction strategy is normalizing. That is, if there is any reduction from a term M to a normal form N, then there is a reduction from M to N in which the leftmost redex is contracted at each step. This is similar to a proof by Klop [28] of a standardization theorem for the untyped lambda calculus plus a left-normal, regular term rewriting system, which generalizes our algebraic rules at the expense of requiring that the rules be non-overlapping, a stronger condition than that they merely be confluent.

2.1 Signatures and terms

The language PCF may be defined over any collection of base types (sorts) and constant symbols. The base types might include natural numbers and booleans or atoms, lists, trees and so on. Since PCF is a typed language, each constant symbol must have a type. Typical constants include the number 3, + for natural number addition, and the list operation cons. A difference between PCF and the pure typed lambda calculus is that we assume a fixed-point constant fix_{σ}: (σ→σ)→σ for each type σ.

Using b to stand for any base type, the type expressions of PCF are defined by the grammar

σ ::= b | σ_{1}→σ_{2} | σ_{1} × σ_{2}.

For example, if nat is a base type, then nat→(nat × nat) is a type. We may avoid writing too many parentheses by adopting the convention that → associates to the right and × has a higher precedence than →. Thus nat × nat→nat→nat is the type of functions which, given a pair of natural numbers, return a numeric function.

3The untyped term ⟨π_{1}(λx. x), π_{2}(λx. x)⟩(λx. x) provides a simple counterexample.

A PCF signature Σ = ⟨B, C⟩ consists of

• a set B whose elements are called base types or type constants, and

• a collection C of pairs ⟨c, σ⟩, where c is called a term constant and σ is an algebraic type expression over B, of the form b_{1}→ … →b_{n}→b for base types b_{1}, …, b_{n}, b, with n ≥ 0.

We require that no term constant appear with more than one type, and that the term constants be disjoint from type constants and other syntactic classes of the language. If ⟨c, σ⟩ ∈ C, then c is said to be a constant symbol of type σ, and we sometimes write c^{σ} when convenient. Note that the base types and term constants must be consistent, in that the type of each constant may only contain the given base types. For example, it only makes sense to have a natural number constant 3^{nat} when we have nat as a base type. Note that constants have the curried type b_{1}→ … →b_{n}→b instead of the more usual type b_{1} × … × b_{n}→b; this is chiefly a matter of preference, since all of the results in this paper hold in either case. The choice of curried functions simplifies some proofs since we do not have to worry about sp-redexes in the arguments of functions.

Before defining the syntax of terms over a given signature, we choose some infinite set V of variables. We will give the well-formed terms and their types using an inference system for typing assertions

Γ ▷ M: τ,

where Γ is a type assignment of the form

Γ = {x_{1}: σ_{1}, …, x_{k}: σ_{k}},

with no x_{i} occurring twice. Intuitively, the assertion Γ ▷ M: τ means that if variables x_{1}, …, x_{k} have types σ_{1}, …, σ_{k} (respectively), then M is a well-formed term of type τ. If Γ is any type assignment, we will write Γ, x: σ for the type assignment

Γ, x: σ = Γ ∪ {x: σ}.

In doing so, we always assume that x does not appear in Γ.

The atomic expressions of PCF over the signature Σ = ⟨B, C⟩ are given by typing axioms. The typing axiom

(cst) ∅ ▷ c: σ, provided ⟨c, σ⟩ ∈ C, or c is fix_{τ} and σ = (τ→τ)→τ

says that each constant symbol c^{σ} is a term of type σ. Variables are given by the axiom

(var) x: σ ▷ x: σ,

which says that a variable x has whatever type it is declared to have. The compound expressions and their types are defined by the following inference rules.

(× Intro)  \frac{Γ ▷ M: σ, Γ ▷ N: τ}{Γ ▷ ⟨M, N⟩: σ × τ}

(× Elim)  \frac{Γ ▷ M: σ × τ}{Γ ▷ π_{1}M: σ, Γ ▷ π_{2}M: τ}

(→ Intro)  \frac{Γ, x: σ ▷ M: τ}{Γ ▷ (λx: σ. M): σ→τ}

(→ Elim)  \frac{Γ ▷ M: σ→τ, Γ ▷ N: σ}{Γ ▷ MN: τ}

(add var)  \frac{Γ ▷ M: σ}{Γ, x: τ ▷ M: σ}

The final rule allows us to add variables to the type assignment.

We say M is a PCF term over signature Σ with type τ in context Γ if Γ▷M: τ is either a typing axiom for Σ, or follows from axioms by the typing rules. We often write Γ ▷ M: τ to mean that “Γ ▷ M: τ is derivable,” in much the same way as one often writes a formula ∀x.P (x) in logic, as a way of saying “∀x.P (x) is true.” A term M is algebraic if it is of base type and is formed from only algebraic constants and variables of base type, using only (→ Elim), i.e., application.

The free and bound occurrences of a variable x in term M have the usual inductive definition. In particular, a variable x occurs free unless it is within the scope of λx, in which case it becomes bound. Since the name of a bound variable is not important, we will generally identify terms that differ only in the names of bound variables. We will write {N/x}M for the result of substituting N for free occurrences of x in M, with renaming of bound variables as usual to avoid capture. We use the notion of a context for substitution without renaming: a context C[ ] for a type σ and variable assignment Γ is a term with a “hole”, such that if Γ ▷ M: σ, then C[M] will be a well-typed term, formed by “plugging” M into the hole.

The following basic lemmas about terms are easily proved; see [35], e.g., for more details.

Lemma 2.1.1 If Γ ▷ M: σ, then every free variable of M appears in Γ.

Lemma 2.1.2 If Γ ▷ M: σ and Γ′ ⊆ Γ contains all the free variables of M, then Γ′ ▷ M: σ.

Lemma 2.1.3 If Γ, x: σ ▷ M: τ and Γ ▷ N: σ are well-typed terms, then so is the substitution instance Γ ▷ {N/x}M: τ.

2.2 Equations and reduction rules

Typed equations have the form

Γ ▷ M = N : τ,

where we assume that M and N have type τ in context Γ. Intuitively, the equation

{x_{1}: σ_{1}, …, x_{k}: σ_{k}} ▷ M = N : τ

means that for all type-correct values of the variables x_{1}: σ_{1} through x_{k}: σ_{k}, expressions M and N denote the same element of type τ.

The equational proof system for PCF is standard, with axiom

(fix)_{eq} Γ ▷ fix_{σ} = λf: σ→σ. f(fix_{σ} f) : (σ→σ)→σ

for each fixed-point operator. We choose this form instead of the more common fix_{σ}M = M(fix_{σ}M) simply to avoid an awkward clash with the (η) reduction rule, since λx: σ→σ. fix_{σ}x could reduce to either λx: σ→σ. x(fix_{σ}x) or fix_{σ}, which would have no common reduct. This is not a serious problem, since the (η) rule will be dropped, but using the (fix) axiom above makes things easier. The remaining axioms, (β)_{eq}, (η)_{eq}, (π)_{eq}, and (sp)_{eq}, resemble the corresponding reduction rules given below. Since we include type assignments in equations, we have an equational version

(add var)  \frac{Γ ▷ M = N : σ}{Γ, x: τ ▷ M = N : σ}

of the structural rule which lets us add an additional typing hypothesis.

Reduction is a “directed” form of equational reasoning that we will adopt as a form of symbolic evaluation. Technically, reduction is a relation on α-equivalence classes of terms. While we are only interested in reducing typed terms, we will define reduction without mentioning types. Since reduction models program execution, this is a way of emphasizing that execution does not depend on the types of terms. We will formulate reduction so that the type of a term does not change as it is reduced.

The “logical” axioms of reduction are

(fix) fix_{σ} ⟶ λf: σ→σ. f(fix_{σ} f)

for fixed-point operators, and the following standard reduction rules for functions and pairs:

(β) (λx: σ.M)N ⟶ {N/x}M

(η) λx: σ.Mx ⟶ M, provided x not free in M

(π) π_{i}⟨M_{1}, M_{2}⟩ ⟶ M_{i}, for i = 1, 2

(sp) ⟨π_{1}P, π_{2}P ⟩ ⟶ P.

We also allow any set R of algebraic rewrite rules of the form M → N, where M and N are algebraic terms over Σ with Γ ▷ M: b and Γ ▷ N: b for some typing context Γ and basic type b. Additional restrictions on M and N are that M may not be a variable and all the variables in N must occur in M. If no variable occurs twice in M, the rule M → N is said to be left-linear, or simply linear. We write E_{R} for the set of all well-typed equations Γ ▷ M = N : b with (M → N) ∈ R.

A term of the form (λx: σ.M)N is a β-redex, λx: σ.Mx is an η-redex, and similarly for (π) and (sp). We say M reduces to N in one step, written M → N, if N can be obtained by applying a single reduction rule to some subterm of M. To emphasize that a rule r is used, we write M →^{r} N. As usual, → → is the reflexive and transitive closure of one-step reduction. A term M is in normal form if there is no N with M → N.

Using Lemma 2.1.3, inspection of the logical rules, and the constraints on variables in algebraic rules, it is easy to show that one-step reduction preserves type.

Lemma 2.2.1 If Γ ▷ M: σ, and M → N, then Γ ▷ N: σ.

It follows by an easy induction that → → also preserves type.

A critical property of reduction systems is confluence, which may be drawn graphically as follows.

[figure: M; P; N_{1}; N_{2}]

In this picture, the top two arrows are universally quantified, and the bottom two existentially, so the picture “says” that whenever M → → N_{1} and M → → N_{2}, there exists a term P such that N_{1} → → P and N_{2} → → P. In lambda calculus, it is traditional to say that a confluent notion of reduction is Church-Rosser, since confluence for untyped lambda calculus was first proved by Church and Rosser [9].

The convertibility relation ↔ on typed terms is the least type-respecting equivalence relation containing reduction. This can be visualized by saying that Γ ▷ M ↔ N : σ iff there is a sequence of terms M_{0}, …, M_{k} with Γ ▷ M_{i}: σ such that

M ≡ M_{0} → → M_{1} ← ← … → → M_{k} ≡ N.

In this picture, the directions of → → and ← ← should not be regarded as significant. (However, by reflexivity and transitivity of → →, the order of reduction and “backward reduction” is completely general.) A few words are in order regarding the assumption that Γ ▷ M_{i}: σ for each i. For pure typed lambda calculus, this assumption is not necessary; if Γ ▷ M ↔ N : σ and Γ ∩ Γ′ mentions all free variables of M and N, then Γ′ ▷ M ↔ N : σ. However, with algebraic rewrite rules this fails.^{4} For conversion as defined here, we have Γ ▷ M ↔ N : σ using rules from R iff E_{R} ⊢ Γ ▷ M = N : σ, regardless of confluence. Therefore, we only mention convertibility in the sequel.

We will write pcf_{0} for the fixed-point and lambda calculus reduction rules (fix), (β) and (π), and write pcf for pcf_{0} + R, where R is our chosen set of algebraic rules. We will write pcf_{η,sp} for pcf + (η) + (sp). Various labelled versions of these reductions will be introduced for technical purposes in the following sections.

2.3 Example: natural numbers and booleans

An example signature for PCF provides booleans and natural numbers. The basic boolean expressions are the constants true and false, and boolean-valued conditional

if ⟨bool⟩ then ⟨bool⟩ else ⟨bool⟩.

The basic natural number expressions include numerals

0, 1, 2, 3, …,

the usual symbols for natural numbers, and addition, written +. Thus if M and N are natural number expressions, so is M + N.

We can also compute natural numbers using conditional tests,

if ⟨bool⟩ then ⟨nat⟩ else ⟨nat⟩,

and compare natural numbers for equality. For example, Eq? 3 0 has the boolean value false, since 3 is different from 0, but Eq? 5 5 = true. To summarize, the basic natural number and boolean expressions may be characterized by the following productions.

⟨bool⟩ ::= true | false | Eq? ⟨nat⟩ ⟨nat⟩ |

if ⟨bool⟩ then ⟨bool⟩ else ⟨bool⟩

⟨nat⟩ ::= 0 | 1 | 2 | … | ⟨nat⟩ + ⟨nat⟩ |

if ⟨bool⟩ then ⟨nat⟩ else ⟨nat⟩

4Consider the algebraic rules fx ⟶ c and fx ⟶ d, for f: a→b. In this case, we do not want ∅▷c ↔ d : b, since the equation c = d is not provable without a variable x of type a.

The equational axioms for natural number and boolean expressions are straightforward. We have an infinite collection of basic axioms

0 + 0 = 0, 0 + 1 = 1, …, 1 + 0 = 1, 1 + 1 = 2, …

for addition, and two axiom schemes for each type of conditional:

                              if true then M else N = M,
                              if false then M else N = N.

There are infinitely many axioms for equality test, determined according to the scheme

Eq? n n = true, each numeral n,
Eq? m n = false, m, n distinct numerals.

Each of these axioms determines a reduction rule, read from left to right. Note that we do not have the equational axiom Eq? M M = true, for arbitrary natural number expression M. The reason is that the more general reduction rule Eq? M M → true is non-linear, and confluence fails.

To see how the reduction rules allow us to evaluate basic natural number and boolean expressions, consider the expression

if Eq? (6 + 5) 17 then (1 + 1) else 27.

We cannot simplify the conditional without first producing a boolean constant true or false. This in turn requires numerals for both arguments to Eq?, so we begin by applying the reduction rule 6 + 5 → 11. This gives us the expression

if Eq? 11 17 then (1 + 1) else 27,

which is simplified using a reduction rule for Eq? to

if false then (1 + 1) else 27.

Finally, one of the rules for conditional applies, and we produce the numeral 27. In order to simplify this expression, we needed to evaluate the test before simplifying the conditional. However, it was not necessary to simplify the number expression 1 + 1 since this is discarded by the conditional. Since we may choose to reduce any subterm at any point, we could have simplified 1 + 1 → 2 between any two of the reduction steps given. With the added flexibility of “nondeterministic choice,” the steps involved mimic the action of any ordinary interpreter fairly closely.

2.4 Confluence of the reduction system pcf

We will now show that pcf -reduction is confluent. Standard techniques for showing confluence in the typed lambda calculus will not work directly, because the fixed-point operator allows terms that have no normal form. Conversely, we can not use results in the untyped lambda calculus such as Mitschke’s delta reduction theorem because we are only assuming that the algebraic rules are confluent and linear. We will proceed by first considering a related system, pcf^{N}, in which recursion is bounded, restoring strong normalization at the cost of diminished computational power.

The system pcf^{N} is formed by replacing the (fix) rule with a family of labelled rules, one for each type σ and natural number n > 0:

(fix^{n}) fix_{σ}^{n} ⟶ (λf: σ→σ. f(fix_{σ}^{n−1} f)).

In the absence of algebraic rules, the effect of this is to limit the number of times each fixed-point operator may reduce. The reduction system with no algebraic rules will be denoted pcf _{0}^{N}. Our first task will be to prove that pcf _{0}^{N} is confluent. An argument due to Breazu-Tannen [6] will then be used to show that pcf^{N} is confluent, from which we may prove that pcf itself is confluent.

We use the method of logical relations to prove that pcf _{0}^{N} is confluent and strongly normalizing. Following [35], if we can show that a property S of terms (i.e., a type-indexed family of predicates S^{σ} over terms of type σ) is type-closed, then that property holds for all well-formed terms. The appropriate definition of type-closed depends on the types available; for PCF we will need clauses for function and product types. For convenience, we introduce the concept of an elimination context, E[ ], which in the case of PCF is a context with a single hole at the head of some sequence of applications and projections (no abstractions or pairs are allowed). We write S(E[ ]) to mean that S holds for each application argument in E[ ], e.g., if E[ ] ≡ (π_{1}(· N_{1}))N_{2}, then S(E[ ]) is short for S^{σ_{1}}(N_{1}) ∧ S^{σ_{2}}(N_{2}). Then a property S is type-closed for PCF if

• S(E[ ]) implies S^{ρ}(E[X]), where X is any variable or constant of appropriate type

• if S^{τ} (Mx) for any variable x of type σ, then S^{σ→τ} (M)

• if S^{σ}(π_{1}M) and S^{τ} (π_{2}M), then S^{σ×τ} (M)

• if S^{ρ}(E[{N/x}M]) and S^{σ}(N), then S^{ρ}(E[(λx: σ. M)N])

• if S^{ρ}(E[M]) and S^{σ}(N), then S^{ρ}(E[π_{1}⟨M, N⟩]) and S^{ρ}(E[π_{2}⟨N, M⟩]).

Lemma 2.4.1 If a property S of terms is type-closed, then S^{σ}(M) holds for every well-formed term M of type σ.

Proof. We may construct another property P from S such that P implies S and P is an admissible logical relation; the type-closed conditions on S are precisely those needed to show this. Then by the Basic Lemma for logical relations, P^{σ}(M), and hence S^{σ}(M), holds for every M; see [35] for details.

Theorem 2.4.2 The reduction system pcf _{0}^{N} is confluent and strongly normalizing.

Proof. We need to show that the properties CR and SN, which assert that reduction from a term is respectively confluent (Church-Rosser) and strongly normalizing, are type-closed. Most of the conditions are easy to establish. The hardest part is to show that each property satisfies the first condition when X is a labelled fixed-point constant; in each case an induction on the label is required.

Next we prove that the system pcf^{N}, obtained by adding a set R of confluent left-linear algebraic rules to pcf _{0}^{N}, is also confluent. In [6], it is shown that the pure typed lambda calculus (with β-reduction only) remains confluent when any confluent (not necessarily linear) R is added. While the original proof of one lemma has a subtle but reparable bug when non-linear rules are considered [7], we observe that the proof is correct if all the rules in R are linear. Therefore, our confluence proof for pcf^{N} will be based on the original development of [6]. We then use the linearity of R again to prove that pcf itself is confluent; for this argument, linearity is essential.

The following lemma allows us to consider algebraic reductions only on terms in pcf _{0}^{N} normal form. By Theorem 2.4.2, every labelled term M has a unique pcf _{0}^{N} normal form, which we refer to as pcf _{0}^{N} (M).

Lemma 2.4.3

1. If M →^{r} N for r ∈ R, then pcf _{0}^{N} (M) → →^{r} pcf _{0}^{N} (N);

2. If M ⟶^{pcf^{N}} N, then pcf _{0}^{N} (M) → →^{R} pcf _{0}^{N} (N).

Proof.

1. If the rule r is s→t and the variables in s are x̄ ≡ x_{1} … x_{n}, then there must be a context C[ ] and terms Q_{1} … Q_{n} such that M ≡ C[{Q̄/x̄}s] and N ≡ C[{Q̄/x̄}t]. Let z be a new variable of the same type as (λx̄: σ̄. s), and define P ≡ pcf _{0}^{N} (C[zQ̄]). Then

M ← ⟵^{pcf _{0}^{N}} {(λx̄: σ̄. s)/z}C[zQ̄] ⟶^{pcf _{0}^{N}} {(λx̄: σ̄. s)/z}P,

and similarly N ⟷^{pcf _{0}^{N}} {(λx̄: σ̄. t)/z}P. Observe that, since zQ̄ is of base type, every occurrence of z in P must be at the head of a subterm of base type; it is then easy to show by induction on the structure of such terms that

pcf _{0}^{N} ({(λx̄: σ̄. s)/z}P) → →^{r} pcf _{0}^{N} ({(λx̄: σ̄. t)/z}P).

Since pcf _{0}^{N} (M) ≡ pcf _{0}^{N} ({(λx̄: σ̄. s)/z}P) and similarly for pcf _{0}^{N} (N), we are done.

2. Follows directly from 1 by induction on the length of the reduction.

Lemma 2.4.4 R-reduction is confluent on labelled terms in pcf _{0}^{N} normal form.

Proof. By induction on the length of a normal form M we show that R is confluent from M. In the base case, M is a variable or fix_{σ}^{0}, whence no R-reductions apply, or M is an algebraic constant, for which we know R is confluent.

Now assume that confluence holds from all pcf _{0}^{N} normal forms strictly shorter than M. If M is an abstraction or a pair, then R-reduction can only affect a proper subterm of M, so confluence holds by the induction hypothesis. The remaining case is that M consists of some sequence of applications and projections of a head variable or constant h, i.e., M ≡ E[h] for some elimination context E[ ], where all the application arguments P_{1} … P_{n} are pcf _{0}^{N} normal forms strictly shorter than M.

If h is a variable or fix_{τ}^{0}, then R-reduction will only take place within the arguments P_{1} … P_{n}, so confluence holds by the induction hypothesis. If h is an algebraic constant, then because of its type E[ ] must consist entirely of applications, so M ≡ hP̄. If M is not of base type then we are in the same situation as if h were a variable, so confluence holds.

Finally, if M ≡ hP̄ is of base type, then it may be decomposed as {Q̄/x̄}s, where s is algebraic, x_{1} … x_{m} are new variables of base type, and Q_{1} … Q_{m} are pcf _{0}^{N} normal forms of base type, each with a variable or fix_{σ}^{0} in head position. Breazu-Tannen calls this an algebraic trunk decomposition in [7]. If M is algebraic then confluence holds by assumption about R. Otherwise, we notice that Q_{1} … Q_{m} and s are all strictly shorter pcf _{0}^{N} normal forms, and that M → →^{R} N only if N ≡ {R̄/x̄}t, where s → →^{R} t and Q_{i} → →^{R} R_{i}, for i = 1 … m. We may prove this by induction on the length of the reduction M → →^{R} N, noting that because we assume that R is left-linear we avoid the problem with this step which was pointed out in [7]. Thus confluence holds from M by the induction hypothesis, and the induction is complete.

These two lemmas now let us prove that pcf^{N} is confluent. As a corollary, we use the linearity of the rules in R to show that pcf itself is confluent.

Theorem 2.4.5 pcf^{N} -reduction is confluent on all labelled PCF terms.

Proof. For any terms M, N, and P, if N ← ⟵^{pcf^{N}} M ⟶^{pcf^{N}} P, then by Lemma 2.4.3 we know that

pcf _{0}^{N} (N) ← ←^{R} pcf _{0}^{N} (M) → →^{R} pcf _{0}^{N} (P).

Lemma 2.4.4 then asserts that there is a Q such that

pcf _{0}^{N} (N) → →^{R} Q ← ←^{R} pcf _{0}^{N} (P).

Since N ⟶^{pcf^{N}} pcf _{0}^{N} (N) and P ⟶^{pcf^{N}} pcf _{0}^{N} (P), we thus have that N ⟶^{pcf^{N}} Q ← ⟵^{pcf^{N}} P.

Corollary 2.4.6 pcf -reduction is confluent on all PCF terms.

Proof. For any terms M, N, and P, if N ← ⟵^{pcf} M ⟶^{pcf} P, then there are corresponding labelled terms

M^{∗}, N^{∗}, and P^{∗} such that N^{∗} ← ⟵^{pcf^{N}} M^{∗} ⟶^{pcf^{N}} P^{∗}. To see this, let m be the length of the longer of the two pcf -reduction sequences from M, and form M^{∗} by labelling each fix_{σ} in M with m; then mimic the two reductions from M by replacing (fix) steps with (fix^{n}) steps, for appropriate choices of n. Now, since pcf^{N} is confluent, N^{∗} and P^{∗} must have a common reduct Q^{∗}; erasing the labels in Q^{∗} gives a term Q such that N ⟶^{pcf} Q ← ⟵^{pcf} P, hence pcf is confluent.

The proof of this corollary uses linearity in asserting that a single labelled term M^{∗} will permit both reductions from M to be mimicked. This property fails in the presence of non-linear rules because a reduction step may then require that two subterms have identical labels. An example of the problem, using (sp), is the term M^{∗} ≡ ⟨π_{1}(fix_{σ}^{m} I), π_{2}(fix_{σ}^{n} I)⟩, where I ≡ (λx: σ. x), and σ is a product type. Consider the following two reduction sequences:

M ⟶^{sp} fix_{σ}^{m} I

and

M ⟶^{fix^{n}} ⟨π_{1}(fix_{σ}^{m} I), π_{2}((λf: σ→σ. f(fix_{σ}^{n−1} f))I)⟩
⟶^{β} ⟨π_{1}(fix_{σ}^{m} I), π_{2}(fix_{σ}^{n−1} I)⟩
⟶^{sp} fix_{σ}^{m} I.

In the first case, the (sp) step requires that m = n, while in the second case we must have m = n − 1, hence there is no such M^{∗}.

2.5 Postponement

In this section, we analyze the reduction system pcf_{η,sp}. Our main technical tool is a postponement theorem for (η) and (sp), which is proved following the pattern for postponement of (η) in the untyped lambda calculus [1]. While (sp) postponement fails for untyped lambda terms (as noted in the introduction), we are able to prove postponement for typed PCF terms. The main “trick” in the proof is to find the correct analogy between sp-reduction and η-reduction. The postponement theorem will be used in the next section to show that pcf is sufficient to compute the pcf_{η,sp} normal form of any program, i.e., any closed term of base type (in fact, programs may have free variables as long as they are of algebraic type, since they act like algebraic constants with no associated reductions).

To show postponement of (η) and (sp) for pcf_{η,sp}, we will use the related system pcf^{lab}, in which η- and sp-redexes are represented as labels. We add term formation rules to allow M^{η} whenever M is a term of function type, and M^{sp} whenever M is of product type; substitution is then extended in the natural way. We also define two functions from labelled to unlabelled terms: |·| and φ. The action of |·| is simply to erase all the labels, while φ replaces labelled subterms with the corresponding redexes: φ(M^{η}) = (λx: σ. φ(M)x) if M: σ→τ, and φ(M^{sp}) = ⟨π_{1}φ(M), π_{2}φ(M)⟩. Finally, the reduction system pcf^{lab} is defined by lifting pcf to labelled terms and adding the following contractions:

(act η) M^{η}N ⟶ MN (act sp) π_{i}M^{sp} ⟶ π_{i}M, for i = 1, 2

(int η) (λx: σ. M)^{η} ⟶ (λx: σ. M)

(int sp) ⟨M, N⟩^{sp} ⟶ ⟨M, N⟩.

The effect of the first two rules is to simulate the reduction of “active” η- and sp-redexes, i.e., those that are also top-level constituents of β- or π-redexes. The other two rules mimic the situation where an η- or sp-redex is reduced internally by (β) or (π), e.g.,

λx: σ. (λx: σ. M)x⟶^{β}λx: σ. M;

these two rules are not necessary for the postponement proof, but they will be needed in the next section and there is no harm in adding them here.

We will now prove a series of lemmas relating pcf^{lab} to the unlabelled systems. The first three are easy inductions, either on the length of a reduction or on the structure of a term.

Lemma 2.5.1 If P ⟶^{pcf lab} P′, then φ(P) ⟶^{pcf} φ(P′).

Proof. This follows by an easy induction on the length of the pcf^{lab} reduction. The (act η) steps may be simulated in the unlabelled reduction by (β) steps, since the η-redexes involved are active; similarly, the (act sp) steps become (π_{i}) steps. The two internal rules may also be simulated, because β- and π_{i}-redexes are created by φ. Any other reduction step corresponds directly to a similar reduction on the unlabelled term.

Lemma 2.5.2 φ(P′) ⟶^{η,sp} |P′|.

Proof. Another easy induction, this time on the structure of P′. Each η- or sp-redex introduced by φ can obviously be reduced to get to |P′|.

Lemma 2.5.3 If |P | ⟶^{pcf} N, then there exists a term P′ such that P ⟶^{pcf lab} P′ and |P′| ≡ N.

Proof. The pcf reduction to N can be simulated on P because whenever a label is in the way it must indicate an active redex, so it can be erased by one of the extra rules in pcf^{lab}.

Lemma 2.5.4 If M ⟶^{η,sp} M′ ⟶^{pcf} N, then there exists a term Q such that M ⟶^{pcf} Q ⟶^{η,sp} N.

Proof. Either M ≡ C[(λx: σ. Lx)] and M′ ≡ C[L], or M ≡ C[⟨π_{1}L, π_{2}L⟩] and M′ ≡ C[L], for some context C[ ] and term L. In the first case, take P ≡ C[L^{η}]; in the second case, take P ≡ C[L^{sp}]. Then M ≡ φ(P) and

M′ ≡ |P |. By Lemma 2.5.3, there is a term P′ such that P ⟶^{pcf lab} P′ and |P′| ≡ N. Then by Lemma 2.5.1 we find that M ≡ φ(P) ⟶^{pcf} φ(P′). Since by Lemma 2.5.2, φ(P′) ⟶^{η,sp} |P′| ≡ N, we may take Q ≡ φ(P′).

From this lemma we may now prove the postponement of (η) and (sp) in pcf_{η,sp}.

Theorem 2.5.5 If L ⟶^{pcf_{η,sp}} N, then there is a term M such that L ⟶^{pcf} M and M ⟶^{η,sp} N.

Proof. Given a reduction sequence from L to N, we may use the previous lemma to push all the (η) and (sp) steps to the end.

In the special case that N is a program in pcf_{η,sp} normal form, which we refer to as a result, we find that the reductions (η) and (sp) are unnecessary:

Corollary 2.5.6 If L ⟶^{pcf_{η,sp}} R and R is a result, then L ⟶^{pcf} R.

Proof. By Theorem 2.5.5 there is an M such that L ⟶^{pcf} M ⟶^{η,sp} R; we will proceed by induction on the length of the reduction from M to R. If the last step in this reduction is P ⟶^{η,sp} R, with Q the redex in P and Q′ its contractum in R, then assume first that Q is passive. Thus Q′ is of non-base type and it cannot be the head of an application or the object of a projection; if it is in the body of an abstraction or a pair, then there is a larger subterm of R that is of non-base type. Consider the largest such enclosing subterm of non-base type (possibly Q′ itself). Since R is a normal form of base type, this subterm must be in the argument of an application. But algebraic constants only take base type arguments, and the presence of a fix contradicts R being in normal form, so the head of the application must be a variable. This is also impossible, because there are no free variables in R (except perhaps of algebraic type), and a surrounding abstraction would give yet a larger subterm of non-base type. Hence Q must be active, so P ⟶^{pcf} R and we may use Lemma 2.5.4 to push this step in front of the (η) and (sp) steps; it is easy to see by the form of Q that this will not increase the number of remaining (η) and (sp) steps.

2.6 The result property

Although pcf_{η,sp} is not confluent, there are other properties of reduction that might be considered as plausible substitutes. In this section, we will show that pcf_{η,sp} has a weaker result property. To put this property in perspective, we might consider three general properties of reduction, in order of decreasing strength. These are confluence, the so-called normal form property of [29], which says that if Γ ▷ M ↔ N : σ and N is a normal form, then M → → N, and the uniqueness of normal forms. It is not hard to see that confluence implies the normal form property, and the normal form property implies that each term has at most one normal form. While Klop and de Vrijer have shown that the normal form property fails in untyped lambda calculus with surjective pairing [29], we will show that typed PCF has a modified version of this property, which we call the result property.

The result property, proved in Theorem 2.6.4 below, states that if M is pcf_{η,sp} convertible to a result N (see Section 2.5), then M is pcf_{η,sp} reducible to N. Since conversion is equivalent to provable equality in the full PCF proof system, it follows by Corollary 2.5.6 that if a term M is provably equal to a result N, then M ⟶^{pcf} N. Furthermore, it follows from the result property and postponement that (η) and (sp) are sound equational rules for reasoning about pcf observational congruence. Thus, when combined with other properties of pcf_{η,sp} and pcf reduction, the result property not only gives a certain coherence to pcf_{η,sp} reduction, but relates provable equality using (η) and (sp) to program execution without these “non-computational” rules.

We will prove the result property using a series of lemmas similar to those used to show postponement in Section 2.5. The same labelled system pcf^{lab} will be used, and here the internal rules will be important.

Lemma 2.6.1 If P ⟶^{pcf lab} P′, then |P | ⟶^{pcf} |P′|.

Proof. This is almost trivial; any of the extra reductions in pcf^{lab} not in pcf may be ignored because all of the labels have been erased.

Lemma 2.6.2 If φ(P) ⟶^{pcf} R and R is a result, then there exists a term P′ such that P ⟶^{pcf lab} P′ and φ(P′) ≡ |P′| ≡ R.

Proof. Since there are no η- or sp-redexes in R, there will be no labels left in P′. Therefore, we will have φ(P′) ≡ |P′|, and every descendent of a redex in φ(P) corresponding to a label in P must eventually either pcf -reduce or be erased. The pcf -reductions will correspond to cases where a redex either is active or reduces internally; they may thus be simulated by the labelled reduction. One complication comes in simulating the reduction step ⟨π_{1}M, π_{2}M⟩→⟨π_{1}M′, π_{2}M⟩; there is no reduction on the corresponding labelled term M^{sp} that matches this, but since pcf is confluent and R is in normal form, we know that the two components of the pair will eventually reduce to the same normal form (or the entire pair will be erased), so we may arbitrarily choose to follow only reductions to the first component.

The other situation which requires care is when there are rules in R of the form (fM_{1} … M_{k−1}x)→N; i.e., rules that accept an arbitrary rightmost argument. If P ≡ (fM_{1} … M_{k−1})^{η}, then φ(P)→(λx: b. N), but P does not pcf^{lab}-reduce. This case is ruled out by the condition that R be a result, however, because reasoning similar to that in the proof of Corollary 2.5.6 shows that algebraic constants in R must always be at the head of subterms of base type. Hence we may simulate the pcf reduction in the labelled system.

Lemma 2.6.3 If M ⟶^{η,sp} M′ and M ⟶^{pcf} R, where R is a result, then M′ ⟶^{pcf} R.

Proof. Take P as in Lemma 2.5.4, so that M ≡ φ(P) and M′ ≡ |P |. By Lemma 2.6.2, there is a term P′

such that P ⟶^{pcf lab} P′ and φ(P′) ≡ |P′| ≡ R. By Lemma 2.6.1 we find that M′ ≡ |P | ⟶^{pcf} |P′|, so we are done.

Now we may prove the result property for pcf .

Theorem 2.6.4 If Γ ▷ N ⟷^{pcf_{η,sp}} R : σ and R is a result, then N ⟶^{pcf} R.

Proof. We will prove that if L ⟶^{pcf_{η,sp}} N and L ⟶^{pcf_{η,sp}} R, where R is a result, then N ⟶^{pcf} R; this is easily seen to be equivalent. By the postponement theorem there is a term M such that L ⟶^{pcf} M ⟶^{η,sp} N; by the corollary to postponement, L ⟶^{pcf} R. Now, since pcf is confluent and R is in normal form, we know that M ⟶^{pcf} R. Using Lemma 2.6.3 once for each reduction step from M to N, we find that N ⟶^{pcf} R.

As a corollary to this theorem, we will show that the equational forms of (η) and (sp) are sound for reasoning about observational congruence. First we define a program context for a given type σ and variable assignment Γ to be a context P[ ] such that P[M] is a program whenever Γ▷M: σ. We say that two terms M and N of the same type σ and variable assignment Γ are observationally congruent, written Γ ▷ M ≃ N: σ, if for every program context P[ ] for σ and Γ, P[M] pcf -reduces to a result R iff P[N] ⟶^{pcf} R. In other words, M and N are completely interchangeable when computing the result of a program.

Corollary 2.6.5 The equational axioms (η)_{eq} and (sp)_{eq} are sound for ≃.

Proof. To show that (η) is sound, we need to show that for any term M of type σ→τ over a variable assignment Γ, with x a variable not free in M, we have Γ ▷ (λx: σ. Mx) ≃ M: σ→τ. If P[ ] is a program

context for σ→τ and Γ, then obviously Γ ▷ P[(λx: σ. Mx)] ⟷^{pcf_{η,sp}} P[M] : σ; if P[(λx: σ. Mx)] pcf -reduces

to a result R, then we also have that Γ ▷ P[M] ⟷^{pcf_{η,sp}} R : σ, and by the previous theorem we find that P[M] ⟶^{pcf} R. The same argument in reverse shows that if P[M] ⟶^{pcf} R, then P[(λx: σ. Mx)] ⟶^{pcf} R. Similar reasoning shows that (sp) is sound.

2.7 Expansion

An alternate approach to avoiding the non-confluence of the full reduction system was suggested to the author after the rest of this chapter was originally written. If, instead of directing the extensional axioms from left to right to obtain the contraction rules (η) and (sp), one orients them from right to left, then the resulting expansion rules are considerably better-behaved. We will refer to the reduction system consisting of pcf plus the two expansion rules

(η)_{exp} M ⟶ λx: σ. Mx, for x not free in M

(sp)_{exp} P ⟶ ⟨π_{1}P, π_{2}P ⟩

as pcf_{exp}. Naturally, for the right-hand sides of these rules to be well-typed, M must be a term of function type (with argument type σ) and P must be a term of product type.

At first glance, using the expansion forms of these rules might seem worse than the previous contraction rules, since they allow infinite reduction sequences such as

f ⟶ λx: σ. fx ⟶ λx: σ. (λy: σ. fy)x ⟶ ….

However, in the third term of this sequence we have created a β-redex which, if reduced, will return the sequence to λx: σ. fx. In general this will be true — after some point in a sequence of expansion steps any further expansions will be reversible. If we restrict application of the expansion steps to cases where no β- or π-redexes are created, then such infinite reductions will be avoided. More formally, we will take an η-expansion redex to be a subterm M of function type which is neither an abstraction nor the head of an application, and an sp-expansion redex to be a subterm P of product type which is neither a pair nor the object of a projection.

It is not difficult to prove that pcf_{exp} is confluent, following the procedure used in Section 2.4. First we may show that pcf _{exp,0}^{N}, the system with labelled fixed-point constants and no algebraic rules, is confluent and strongly normalizing, either by adapting the logical relations proof discussed previously, or by modifying the proof for a similar system (with iteration instead of labelled fix-reduction) given by Jay [27], which is based on Girard’s “candidats de reducibilité.” The normal forms in this strongly normalizing system are known as long normal forms; for example, the long normal form of a variable f: ρ→σ × τ, where σ and τ are base types, is lnf (f) ≡ λx: ρ. ⟨π_{1}(fx), π_{2}(fx)⟩.

Using long normal forms instead of pcf _{0}^{N} normal forms, Breazu-Tannen’s proof goes through as before to establish that pcf _{exp}^{N} is confluent, provided R is a confluent set of linear algebraic rules. Since the expansion rules are linear, there is then no problem extending this result as above to show that pcf_{exp} itself is confluent.

Theorem 2.7.1 The reduction system pcf_{exp} is confluent.

Since pcf_{exp} is confluent, we immediately find that it satisfies the normal form property.

Corollary 2.7.2 If Γ ▷ M ⟷^{pcf exp}L : σ (or, equivalently, Γ ▷ M ⟷^{pcf_{η,sp}} L : σ), where L is a long normal form,

then M ⟶^{pcf exp}L.

Postponement does not hold in general for the expansion rules. For example, consider the reduction sequence

Ip ⟶^{spexp}⟨π_{1}(Ip), π_{2}(Ip)⟩⟶^{β}⟨π_{1}p, π_{2}(Ip)⟩,

where I ≡ λx: σ×τ. x. The sp-expansion must happen first since the β-contraction only affects one component of the pair. It is not enough to require that the reduction sequence end in a normal form, either. Consider the system with the algebraic rule r: zero x ⟶ 0; in the sequence

zero⟶^{ηexp}λx: nat. zero x⟶^{r}λx: nat. 0,

the final term is in normal form, but the η-expansion step must precede the algebraic step because it creates the algebraic redex (note that we only disallow η-expansions which create β-redexes).

Postponement of the expansion rules does hold for reduction sequences ending in results. However, just as in Corollary 2.5.6, when the final term is a result, all of the extensional steps disappear:

Theorem 2.7.3 If M ⟶^{pcf exp}R, where R is a result, then M ⟶^{pcf} R.

Proof. This is just a special case of the result property for pcf .

Thus we find again that pcf is the proper reduction system for evaluating programs; also, by adding the extensional rules as expansions, we may find normal forms for arbitrary terms which have them.

2.8 Completeness of leftmost reduction

If the set R of algebraic rules satisfies some additional constraints, then we may prove that the leftmost reduction strategy is complete with respect to finding pcf (or pcf_{exp}) normal forms. The extra constraints are that R be terminating and left-normal (which will be defined below). This result is similar to one obtained by Klop [28], who proves that leftmost reduction is normalizing for the untyped lambda calculus plus any left-normal, regular term rewriting system. For a term rewriting system to be regular the rules must be linear and non-overlapping; we take the alternate approach of accepting any confluent set of linear algebraic rules, as long as they are terminating. Our proof is made simpler by this assumption of termination, as well as the isolation of non-termination in the base language to the fixed-point constants; also, we do not pass through the intermediate step of a general standardization theorem.

An algebraic rule is left-normal if all the variables in the left-hand side of the rule appear to the right of all the constants. For example, all of the rules given in Section 2.3 for natural numbers and booleans are left-normal. If we had chosen to permute the arguments of the conditional so that the test was at the end, i.e., so that the reduction rules would be

cond M N true ⟶ M
cond M N false ⟶ N,

then we would not have had a left-normal set of rules. Intuitively, if we have left-normal rules, then we only need to evaluate the arguments of an algebraic term from left to right; it will never be the case that skipping an argument and evaluating one to its right will create an algebraic redex involving the skipped term. In many cases, obtaining left-normal rules is simply a matter of permuting arguments; in some other cases, we may obtain left-normal rules by introducing auxiliary function symbols. For example, consider the following set of rules, where the value of the first argument determines which of the other two arguments is to be evaluated:

f true true N ⟶ true
f true false N ⟶ false
f false M true ⟶ false
f false M false ⟶ true.

An equivalent left-normal system is

f true M N ⟶ M
f false M N ⟶ not N
not true ⟶ false
not false ⟶ true.

This is just the process of determining the sequentiality index of the function defined by the algebraic rules (see [3]) and rearranging arguments so that the index is always the leftmost unevaluated argument. If a function is inherently non-sequential then we will not be able to find a left-normal set of rules; the classic example is the parallel or function, por:

por true N ⟶ true
por M true ⟶ true
por false false ⟶ false

The first lemma we will need formalizes a special case of our intuition about the creation of pcf^{N} redexes when the algebraic rules are left-normal.

Lemma 2.8.1 If the rules R are left-normal, then whenever the leftmost redex R in a labelled term M is contracted by a rule of pcf^{N} to obtain a term N, all of the non-algebraic subterms of M to the left of R will also be to the left of the leftmost redex of N.

Proof. Suppose that P is a non-algebraic subterm of M to the left of R and that contraction of R creates a redex S in N which is to the left of P. No (β), (π) or (fix) rule could be created so far to the left of R, so S must be an algebraic redex which contains the reduct of R, and hence also contains P. The only way an algebraic redex can have a non-algebraic subterm P is if the rule contains a variable covering that position; since the rules are left-normal, this means that the rule also contains a variable covering the position of the reduct of R, which contradicts the fact that S was created by the contraction of R. Therefore P must be to the left of the leftmost redex in N.

We will also need the fact that pcf^{N} is strongly normalizing whenever the set of rules R is terminating. This can be seen as a special case of a theorem of Breazu-Tannen and Gallier [7], where they consider adding a terminating set of algebraic rules to the polymorphic lambda calculus, including the (η) rule. The proof we give is adapted from a simplification of theirs.

Lemma 2.8.2 If the rules of R are terminating, then pcf^{N} is strongly normalizing.

Proof. We will extend the logical relations proof of strong normalization for pcf _{0}^{N} given in Section 2.4. The only significant case we need to consider is showing that SN (E[ ]) implies SN^{ρ}(E[f]), where f is an algebraic constant. That is, if strong normalization in pcf^{N} holds from N_{1}, …, N_{k}, then we need to show that it holds from M ≡ fN_{1} … N_{k}. If the arity of f is greater than k then we are done, so assume that fN_{1} … N_{k} is of base type. Since each term N_{i} is strongly normalizing, and the rules in R are linear, the only way to have an infinite reduction from M is if there is an infinite reduction from fP_{1} … P_{k}, where each P_{i} is the normal form of the corresponding N_{i}. Now, an algebraic reduction cannot create new pcf _{0}^{N} redexes, so this infinite reduction must be all algebraic, contradicting the fact that R is terminating. Therefore M is strongly normalizing.

Using these two lemmas we may now prove the main theorem of this section:

Theorem 2.8.3 If M ⟶^{pcf} N, where N is a normal form and the rules in R are confluent, terminating, left-linear, and left-normal, then there is a pcf reduction from M to N that reduces the leftmost redex at each step.

Proof. If M ⟶^{pcf} N then using the linearity of the rules in R we may find a labelled reduction M^{∗} ⟶^{pcf^{N}} N^{∗} such that M^{∗} and N^{∗} erase to M and N, respectively. Since pcf^{N} is confluent and strongly normalizing, we may find an equivalent leftmost reduction from M^{∗} to N^{∗}. Now, the only way the erasure of this leftmost reduction will not be a leftmost pcf reduction is if there is some subterm fix^{0} to the left of the leftmost redex at some step in the labelled reduction. But by Lemma 2.8.1, this subterm must also be present in N^{∗}, which contradicts the fact that N is a normal form. Therefore we have a leftmost reduction from M to N.

Corollary 2.8.4 If a program P is provably equal to a result R, and the rules in R are confluent, terminating, left-linear, and left-normal, then the leftmost pcf reduction from P will reach R.

Proof. Obvious from the theorem and the result property. In particular, the algebraic rules for natural numbers and booleans given in Section 2.3 satisfy all the restrictions, hence the leftmost reduction strategy will find results of programs over nat and bool. This gives a correspondence between nondeterministic reduction and the deterministic evaluation strategy used in the semantic study of [43], providing a full correspondence between axiomatic, operational and denotational semantics of PCF.

All the results of this section hold for the system with expansion rules. In particular, if any term is provably equal to a long normal form in the full proof system with an appropriate set of algebraic rules, then leftmost pcf_{exp} reduction will find that normal form.

2.9 Conclusion

Since the full reduction system pcf_{η,sp} with (η) and (sp) is not confluent, we consider the more limited system pcf to be more appropriate for PCF execution. The system pcf includes fixed-point rules (fix), lambda calculus rules (β) for function calls and (π) for pairs, and any set R of left-linear, confluent algebraic rules. We have shown that pcf reduction is confluent and demonstrated several connections between pcf and pcf_{η,sp}. The first is that (η) and (sp) rules may be postponed in pcf_{η,sp} reduction, and so whenever a closed term of base type pcf_{η,sp} reduces to normal form, this reduction may be accomplished without (η) or (sp). Thus, if we consider programs to be closed terms of base type (or any product of such types), pcf is equivalent for the purpose of program execution to the apparently stronger but non-confluent pcf_{η,sp}. We also prove a result property of pcf_{η,sp} in Section 2.6, from which it follows that (i) whenever a term is provably equal (in the full system) to a result, the term reduces to this result by pcf reduction, and (ii) all equational rules, including (η)_{eq} and (sp)_{eq}, are sound for pcf observational congruence. We consider adding expansion rules for (η) and (sp), showing that the resulting system is confluent and adequate for finding long normal forms of arbitrary terms. We also show that a leftmost reduction strategy is complete for pcf reduction if the algebraic rules satisfy the additional constraints that they are terminating and left-normal. In summary, these technical results suggest that while the full equational proof system is a natural “axiomatic semantics” for PCF, a more limited reduction system has more desirable technical properties and seems suitable as a corresponding operational semantics.

One open problem is to extend our confluence theorem to include reduction rules for non-algebraic terms. For example, we might like to give reduction rules for the evaluation of some higher-order function, and be sure that the resulting extension of pcf is confluent. Presumably our current proof already applies to some cases of this form, but we have not yet done a careful analysis.

Inductive and Projective Types

In this and the next chapter we consider two related typed λ-calculi which allow the construction of types as fixed points of recursive type expressions. The smaller system, λ^{μν}, restricts the recursion so that all functions definable in the system are total. It is still quite powerful, however; it is more expressive than Gödel’s system T, since not only are all the functions that are provably total in Peano arithmetic definable, but also many that are not. The larger calculus, λ^{⊥ρ}, contains all of the types and terms of λ^{μν}, plus it allows more general recursive types by including a lifting constructor to explicitly mark the types where non-termination is allowed; as a result, all computable partial functions are definable. By separating out the recursive types which only allow bounded computations, we obtain a finer resolution of where nontermination is possible than that provided by other type systems. In particular, we compare our work to Plotkin’s versions of PCF [43, 44] and Hagino’s Categorical Data Types [21, 22]. Indeed, our work may be viewed as an extension of Hagino’s language, which is roughly equivalent in expressive power to λ^{μν}, into a system equivalent in power to PCF. The existence of a clean category theoretic semantics for the language has been the motivating force behind a number of design decisions; we will also discuss these choices and some of the alternatives.

When trying to give a categorical semantics to a functional language with recursion as well as product and sum types, it is well-known that something must be given up. Specifically, if a cartesian closed category has an initial object 0 (the identity for the sum) and if there is a solution to the equation X ≅ X→0, then every object will be isomorphic and all arrows will be equal.^{1} The standard solution is to drop the requirement of full categorical sums. For example, the category of complete pointed partial orders and total continuous functions (CPPO) has a categorical product and solutions of all recursive domain equations (RDEs), but only has the “coalesced” sum, which identifies the bottom elements of the summands — this loss of information leads to the sum not being “extensional,” in the sense of every element of the sum type being uniquely expressible as the injection of an element of one of the summands. On the other hand, Plotkin’s category CPO^{⇀} of complete (not necessarily pointed) partial orders and partial continuous functions has extensional sums and solutions to all RDEs, but the cartesian product is not the categorical product; there is a categorical product, but it is not adjoint to the function space functor. A third alternative, which we adopt, is to drop the requirement that every RDE have a solution; an example of this approach is the category CPO of complete partial orders and total continuous functions, which is cartesian closed and has full categorical sums, but only a restricted class of RDEs has solutions. It is this last category which provides the motivation for the calculi we study here.

1Using terms in the language we develop below, if we have a type X such that X ≅ X→0, then the closed term ω ≡ λx: X. unfold_{X} xx has type X→0. Therefore, the term Ω ≡ ω(fold_{X} ω) is a closed term of type 0 (which is essentially a typed version of the classical combinator Ω, the simplest term with no normal form). It is then easy to see that the terms λx: 1. Ω and λy: 0. ◇ are inverses, hence 0 ≅ 1; it follows that every type A is isomorphic to 0, since A ≅ A × 1 ≅ A × 0 ≅ 0. For another approach to the proof, see for example [31], section I.8.

In the approach we take to giving a categorical model for a typed functional language, the objects of the category represent the types and the arrows represent terms, where the source gives the type of the free variables and the target gives the resulting type of the term. A type expression with a free type variable then becomes an endofunctor, with the action of the functor on an object being given by substitution of the corresponding type for the free variable (we will describe the action on an arrow later). Given a type expression σ with a free type variable t, corresponding to a functor F, a solution to the RDE t = σ is a type τ such that τ is isomorphic to σ with τ substituted for t (written τ ≅ {τ/t}σ). That is, a solution is an object X such that X ≅ F X, i.e., a fixed point of F. Common notation for the type τ so constructed is μt. σ; we will often write μF when we are particularly thinking of σ as a functor.

In a category with an initial object 0 and colimits of ω-chains, a fixed point of an endofunctor F which preserves such colimits (i.e., an ω-cocontinuous functor) may be found as the colimit of the chain

0 ⟶^{□} F 0 ⟶^{F □} F^{2}0 ⟶^{F^{2}□} …,

where □ is the unique arrow from 0 to F 0. The fixed point μF found by this method is the least one, in the sense that it is the initial object in the category of F -algebras (whose objects are arrows f: F A→A in the original category; an arrow between f and g: F B→B is an arrow h: A→B such that f; h = F h; g). Since a colimit is also known as an inductive limit, we refer to the types constructed in this manner as inductive types. Dually, in a category with a terminal object 1 and limits of ω-chains, we find the greatest fixed point (which is terminal in the category of F -coalgebras) of an ω-continuous endofunctor by taking the (projective) limit of

1 ⟵^{◇} F 1 ⟵^{F ◇} F^{2}1 ⟵^{F^{2}◇} …,

where ◇ is the unique arrow from F 1 to 1. Thus, the projective types are the greatest solutions to their corresponding RDEs; we write νt. σ or νF for these.

The language λ^{μν} studied in this chapter contains type constructors for the inductive and projective types as well as function spaces and finite sums and products. The class of functors for which we will be able to find fixed points is those which can be built from these constructors and which are strictly covariant in their argument (that is, the argument can only be used to the right of any function space constructors; the functor F X = ((X→A)→B) is not allowed). All the functors in this restricted class are ω-(co)continuous over Set, the category of sets and total functions, so finding a model for λ^{μν} will not require the machinery of cpo’s that will be used in the next chapter.

We have already mentioned the work of Hagino above; his language CPL [21] and the related typed λ-calculus with categorical type constructors [22] start from the very general concept of F, G-dialgebra and, through various computationally-imposed restrictions, result in a language with a type system equivalent to that of λ^{μν}, although with a more elegant (but less practical) notation. More recently, a language almost identical to λ^{μν} has been studied by Greiner [19]; his primary concern is to show examples of types and programs that may be written in the language. Greiner also discusses the problem that arises when inductive and projective (which he calls co-inductive) types are simulated in a language such as Girard’s system F, namely that the types are no longer extensional and so certain algorithms (most famously, the constant-time predecessor operation on the Church numerals) are not expressible. He makes the same observation which we make (independently) in Section 3.4, that a simple addition to our language allows us to express these algorithms with the desired efficiency.

3.1 Syntax of the language λ^{μν}

In this section we will describe the syntax for the types and terms of λ^{μν}. We will continue to use σ, τ, and υ as metavariables for type expressions, s and t for type variables, M and N for arbitrary terms, and x for (regular) variables. Type expressions may be any of the following:

t | 0 | 1 | σ + τ | σ × τ | σ→τ | μt. σ | νt. σ.

The types of the language will be the closed type expressions, i.e., those with no free type variables. Thus, the expression t is not a type on its own, but may be used only as a bound variable in the body of a μt or νt constructor. The type 0 is to be thought of as the empty type; it is the identity for the sum, that is, 0 + σ ≅ σ + 0 ≅ σ for any type σ. The type 1 has just one element; it is the identity for the product, ×. The unit type also serves as a left identity for the function space constructor, since 1→σ ≅ σ. We will follow the same grouping conventions as in the previous chapter, adding the convention that + associates to the left and has a precedence between that of × and that of →; thus, the fully parenthesized form of 1 + s + t × t→s is ((1 + s) + (t × t))→s.

Not every type expression σ may be the body of an inductive (μ) or projective (ν) type — the bound type variable t may only occur strictly positively in σ, that is, it may not appear in any subterm on the left of an arrow. This is stronger than saying that σ must be covariant in t, which only requires that t always occur positively, i.e., to the left of an even number of arrows. We will relax this restriction somewhat in the next chapter, but the relaxed condition adds nothing to the types we can define in λ^{μν}. What we are avoiding by demanding strict positivity are types such as μt. ((t→bool)→bool), where bool ≡ 1 + 1; since our interpretation of a type in λ^{μν} is a discrete cpo, i.e., a set, there can be no solutions to such equations by cardinality considerations (the cardinality would be some κ such that κ = 2^{2^{κ}}, which is impossible in standard set theory).

As for PCF in the previous chapter, we give an inference system for typing assertions Γ ▷ M: σ for well-formed terms of λ^{μν}. We start with the rules for variables, which are the same as for PCF:

(var) x: σ ▷ x: σ

(add var)  \frac{Γ ▷ M: σ}{Γ, x: τ ▷ M: σ.}

The categorical interpretation of a term Γ▷M: σ is an arrow from γ to σ, where γ is (the object corresponding to) the type σ_{1} × … × σ_{n} if Γ is the type assignment {x_{1}: σ_{1}, …, x_{n}: σ_{n}}. According to this interpretation, the (var) rule gives the identity arrow for σ. Composition of arrows is given by substitution — if f: γ→σ is the arrow represented by Γ ▷ M: σ and g: σ→τ is the arrow represented by x: σ ▷ N: τ, then their composition g ∘ f: γ→τ is given by the term Γ ▷ {M/x}N: τ. The situation is slightly complicated because we may wish to have more than one free variable in N; thus, if we have g′: γ′ × σ→τ corresponding to Γ′, x: σ ▷ N: τ, then the substitution Γ′, Γ ▷ {M/x}N: τ represents the composite arrow g′ ∘ (γ′ × f): γ′ × γ→τ. The (add var) rule allows us to form the appropriate projections for this scheme of multiple free variables to work, since if Γ ▷ M: σ is the arrow f: γ→σ, then Γ, x: τ ▷ M: σ is the composite f ∘ π_{γ}: γ × τ→σ, where π_{γ}: γ × τ→γ is the projection which drops the last component of type τ.

The constants and term constructors corresponding to the given type constructors also come from the categorical interpretation of the types. The type 0 is meant to represent an initial object, so there must be an arrow from 0 to any other type υ:

(0 Elim) ∅ ▷ □^{υ}: 0→υ.

The sum type σ + τ requires two injection arrows,

(+ Intro_{1}) ∅ ▷ ι_{1}^{σ+τ}: σ→σ + τ

(+ Intro_{2}) ∅ ▷ ι_{2}^{σ+τ}: τ→σ + τ, as well as, for every pair of arrows with a common target, an arrow from the sum of their sources into that target:

(+ Elim)  \frac{Γ ▷ M: σ→υ, Γ ▷ N: τ→υ}{Γ ▷ [M, N]: σ + τ→υ.}

Dually, the type 1 represents a terminal object, and σ × τ is a product, so we get the following axioms and rules:

(1 Intro) Γ ▷ ◇: 1

(× Elim_{1}) ∅ ▷ π_{1}^{σ×τ}: σ × τ→σ

(× Elim_{2}) ∅ ▷ π_{2}^{σ×τ}: σ × τ→τ

(× Intro)  \frac{Γ ▷ M: σ, Γ ▷ N: τ}{Γ ▷ ⟨M, N⟩: σ × τ.}

Note that in the introduction rules for 1 and × the source of the arrows is Γ, whereas the other constants and the elimination rules for 0 and + are given in a “curried” form, i.e., the term created has a functional type corresponding to the desired arrow type. This is a purely stylistic decision; we could have written the + elimination rule, for example, as

(+ Elim′)  \frac{Γ, x: σ ▷ M: υ, Γ, y: τ ▷ N: υ}{Γ, z: σ + τ ▷ (case z of ι_{1}^{σ+τ} x. M, ι_{2}^{σ+τ} y. N): υ;}

the disadvantage of this approach is that we would have two basic constructions which bind variables, which adds to the complexity of the system. Conversely, we could have curried the 1 introduction rule as

(1 Intro′) ∅ ▷ unit^{υ}: υ→1,

but then we would have no simple expression for a closed term of type 1 (the simplest would be something like unit^{1→1} unit^{1}). Finally, we write the other constants with empty type assignments, which makes them arrows from 1, that is, elements of the objects corresponding to their types; by using the (add var) rule we may construct constant terms for any desired type assignment Γ. We could have taken this approach for ◇, but then its status as the unique arrow from a given type to the terminal object would have been obscured. All of these design decisions are for the most part non-issues because we are intending to work in a system where all of the extensional rules hold, hence all of the necessary isomorphisms exist.

Continuing with the syntax of the language, we have the usual λ-abstraction and application rules:

(→ Intro)  \frac{Γ, x: σ ▷ M: τ}{Γ ▷ (λx: σ. M): σ→τ}

(→ Elim)  \frac{Γ ▷ M: σ→τ, Γ ▷ N: σ}{Γ ▷ MN: τ.}

In light of the above discussion of the categorical basis for the syntax, we observe that abstraction is the process by which an arrow may be “curried” on one of its free variables to obtain an internal arrow, i.e., an element of a functional type. Application then provides the means of composing these internal arrows with other terms; also, a combination of the variable rules and application has the effect of “uncurrying” a function, e.g., x: 0 ▷ □^{υ}x: υ is the uncurried form of the (0 Elim) axiom.

Finally, we have the terms associated with the inductive and projective types. The categorical interpretation of an inductive type μF (≡ μt. σ) is an initial F -algebra, i.e., an arrow φ from F (μF) to μF such that for any other F -algebra f: F (X)→X there is a unique F -algebra morphism h_{f}: φ→f, that is, an arrow h_{f}: μF →X such that the following diagram commutes:

[figure: μF; X; h_{f}; F (μF); F (X); F (h_{f}); φ; f].

In terms of their actions on values of a recursive type, the function φ “folds” up the outermost level of a recursively defined value, while the function h_{f} takes a value of the type and iteratively applies f to each of its levels; this will become clearer when we discuss the equations and give some examples. For now, we simply introduce the following constants corresponding to φ and h_{f} (actually, it_{μF}^{τ} corresponds to the function h which takes an arbitrary F -algebra f and produces the appropriate morphism h_{f}):

(μ Intro) ∅ ▷ fold_{μF}: F (μF)→μF

(μ Elim) ∅ ▷ it_{μF}^{τ}: (F (τ)→τ)→μF →τ.

Recall that we are using F (τ) as an abbreviation for {τ/t}σ, since we are treating the type expression σ with free type variable t as an endofunctor F; the unabbreviated form of the (μ Elim) axiom would be

∅ ▷ it_{μt. σ}^{τ}: ({τ/t}σ→τ)→μt. σ→τ,

which is harder to read.

We have the dual situation for projective types. The interpretation of νF is a terminal F -coalgebra, i.e., an arrow ψ: νF →F (νF) such that for every F -coalgebra g: Y →F (Y) there is a unique arrow k_{g}: Y →νF such that

[figure: F (Y); F (νF); F (k_{g}); Y; νF; k_{g}; g; ψ]

commutes. In this case, the action of the function ψ is to “unfold” a value of a recursive type by one level, and the function k_{g} creates a new value of the recursive type by bundling together the function g with a starting value from Y; again, we will give examples after discussing the equations. The constants corresponding to ψ and k are

(ν Elim) ∅ ▷ unfold_{νF}: νF →F (νF)

(ν Intro) ∅ ▷ new_{νF}^{τ}: (τ→F (τ))→τ→νF.

There are a number of abbreviations, or syntactic sugar, which we will use in the following sections. The first is simply that we will omit sub- and superscripted type information whenever it can reasonably be inferred. Likewise, we will often leave implicit a description of the typing context Γ, and assume that one may be found that allows the given term to be proven to have the desired type. For example, when we say that we will write M ∘ N: σ→υ as an abbreviation for (λx: σ. M(Nx)), where M has type τ→υ, N has type σ→τ, and x does not occur free in either M or N, this assumes that M and N have the given types with respect to some common type assignment. If M has type σ→σ, then we may write M^{(n)} for the n-fold composition (… (M ∘ M) ∘ … ∘ M); when n = 0, this becomes the identity id^{σ} ≡ (λx: σ. x).

We have already been using the notation {M/x}N to indicate the result of substituting the term M for the free variable x in N, and similarly {σ/t}τ for substitution in type expressions. We will not formalize this more here, except to note that λ is the only variable binding operator for terms, and μ and ν are the only binding operators for type expressions. All variables not in the body of an eponymous binding operation are free; the set of free variables in a term M is denoted FV(M). As for PCF, we have the following useful lemmas:

Lemma 3.1.1 If Γ ▷ M: σ is well-formed, then every x ∈ FV(M) appears in Γ.

Lemma 3.1.2 If Γ ▷ M: σ is well-formed, then so is Γ′ ▷ M: σ for every Γ′ ⊂ Γ which contains all the free variables in M.

Lemma 3.1.3 If Γ ▷ M: σ and Γ, x: σ ▷ N: τ are well-formed, then so is Γ ▷ {M/x}N: τ.

We may form arbitrary finite products and sums as follows. The nullary product is ◇: 1 and the nullary sum is □^{υ}: 0→υ. Given terms M_{1}: σ_{1}, …, M_{n}: σ_{n}, for n > 1, we may form the n-ary product ⟨M_{1}, …, M_{n}⟩: σ_{1} ×…×σ_{n} as an abbreviation for ⟨… ⟨M_{1}, M_{2}⟩, …, M_{n}⟩ (remembering that × associates to the left); in the special case n = 1 we may write ⟨M_{1}⟩: σ_{1} as an “abbreviation” for M_{1}. The mth projection of an n-ary product, 1 ≤ m ≤ n, may be found by applying the constant π_{m}^{n} defined as follows:

π_{1}^{1} ≡ id
π_{m+1}^{n} ≡ π_{m}^{n} ∘ π_{1} (n ≤ m)
π_{m+1}^{m+1} ≡ π_{2}.

Similar definitions hold for the n-ary sum, if each of the types σ_{k} is of the form τ_{k}→υ for some fixed type υ. That is, we get the term [M_{1}, …, M_{n}]: τ_{1} + … + τ_{n}→υ as an abbreviation for [… [M_{1}, M_{2}], …, M_{n}], with the special case [M_{1}] ≡ M_{1}. The mth injection ι_{m}^{n} into an n-ary sum is given by

ι_{1}^{1} ≡ id
ι_{m+1}^{n} ≡ ι_{1} ∘ ι_{m}^{n} (n ≤ m)
ι_{m+1}^{m+1} ≡ ι_{2}.

The product constructors allow us to define a pattern-matching version of λ-abstraction. Given n variables x_{1}, …, x_{n} and n types σ_{1}, …, σ_{n}, for n ≥ 0, we write (λ⟨x_{1}: σ_{1}, …, x_{n}: σ_{n}⟩. M) as an abbreviation for

(λp: σ_{1} × … × σ_{n}. {π_{1}^{n}p/x_{1}} … {π_{n}^{n}p/x_{n}}M),

where p is not free in M. We will add other kinds of patterns eventually, so let us speak generally of binding a pattern P in M with the syntax (λP. M). Note that we may generalize the product pattern to have an arbitrary pattern for each component, instead of just the basic pattern x: σ.

Another useful piece of syntactic sugar is the let statement. We will write let P = M in N for the compound term (λP. N)M, where P is a pattern as above. In the case that M is of the form (λQ. M′), in which case P must look like f: σ→τ, we will also write this as let f(Q): τ = M′ in N. As an example, the term let car⟨x: nat, y: bool⟩: nat = x in … is an abbreviation for

let car: nat × bool→nat = (λ⟨x: nat, y: bool⟩. x) in …,

which is itself an abbreviation for (after several substitutions)

(λcar: nat × bool→nat. …)(λp: nat × bool. π_{1}p).

We may use a similar “in-line” form for the n-ary sum, namely the case statement mentioned above in a slightly different form (which we did not want to add as a basic piece of syntax, but which is quite useful as auxiliary syntax). Thus, the term [(λP_{1}. N_{1}), …, (λP_{n}. N_{n})]M may be written out as

case M of ι_{1}^{n}P_{1}. N_{1}, …, ι_{n}^{n}P_{n}. N_{n}.

As an example of the use of several of these abbreviations, we introduce the type of booleans, defined as bool ≡ 1 + 1. There are two values of this type, namely ι_{1}◇ and ι_{2}◇; we will refer to them respectively as true and false. A conditional similar to the term if B then M else N of the previous chapter is then expressible as case B of true. M, false. N, which is certainly more readable than the “unsugared” version, [(λx: 1. M), (λx: 1. N)]B.

We have mentioned several times the interpretation of substitution in a type expression as being the application of a functor to an object; we now describe the effect of applying a functor to an arrow. For our purposes, it will be more useful to apply a functor to an internal arrow, that is, a term of function type; because our intended model is a cartesian closed category, i.e., we have extensional finite products and function spaces, this is entirely equivalent to defining functor application on arbitrary terms and their typing contexts. Thus, given a functor F and a term M: σ→τ, we will produce a term F (M): F (σ)→F (τ). In addition, after the equations are introduced in the next section, we will be able to prove that F (id) = id and F (M ∘ N) = F (M) ∘ F (N), completely justifying our referring to F as a functor. The basic idea for this comes from Hagino [21, 22], although his presentation is somewhat more difficult to read and treats only strictly positive functors. The definition of F (M) will proceed by cases on the structure of F (t), where t is a fresh type variable:

• if F (t) = υ, where t does not occur free in υ, then F (M) = id^{υ};

• if F (t) = t, then F (M) = M;

• if F (t) = G(t) + H(t), then F (M) = [ι_{1} ∘ G(M), ι_{2} ∘ H(M)];

• if F (t) = G(t) × H(t), then F (M) = λ⟨x: G(σ), y: H(σ)⟩. ⟨G(M)x, H(M)y⟩;

• if F (t) = G(t)→H(t), then F (M) = λf: G(σ)→H(σ). H(M) ∘ f ∘ G(M^{op}) (see below);

• if F (t) = μs. G(s, t), then F (M) = it_{μs.G(s,σ)}^{F (τ)}(fold_{μs.G(s,τ)} ∘G(F (τ), M));

• if F (t) = νs. G(s, t), then F (M) = new_{νs.G(s,τ)}^{F (σ)}(G(F (σ), M) ∘ unfold_{νs.G(s,σ)}).

For the system as defined in this chapter, F will always be strictly positive, so the type expression G(t) will not depend on t in the case F (t) = G(t)→H(t) above. For purposes of the next chapter, however, we include the mechanism for dealing with arbitrary covariant functors F. The notation M^{op} is meant to indicate a term of type τ→σ, the opposite of M: σ→τ. Since in general we have no way of forming an opposite term, the only rules we have are that opposite is an anti-involution, i.e., the opposite of the opposite is the original term: (M^{op})^{op} ≡ M, and opposite is contravariant with respect to composition: (M ∘ N)^{op} ≡ N^{op} ∘ M^{op} (from which it is easy to prove that also id^{op} ≡ id). In forming the subterm G(M^{op}), if G is contravariant then by using this rule we will only ever need M; if M^{op} appears in the fully expanded term F (M), then F must not have been covariant.

Note that in the definition of F (M) when F is a recursive type, we treat the body of F as a functor G with two arguments, reflecting the fact that we are keeping track of two free type variables — the variable t for which we are “substituting” M, and the variable s which is bound by the recursive constructor in F. In fact, we may treat a type expression σ with n free type variables as an n-argument functor F; the application F (τ_{1}, …, τ_{n}) represents the simultaneous substitution of the n type expressions for the corresponding variables, and the application to terms is defined essentially as above. We will not go through the details of this extension here, as they will only be used once in the sequel (in the proof that F preserves composition, for the case when F is a recursive type).

Recall that the intended meaning of μF and νF is that they are recursive types, that is, that μF ≅ F (μF) and νF ≅ F (νF), but so far we have only seen arrows giving one direction for each of these isomorphisms. With the aid of the equational proof system given in the next section, we may see that an inverse to fold_{μF} is provided by the term it_{μF}^{F (μF)} F (fold_{μF}): μF →F (μF). We will refer to this term as unfold_{μF}. Similarly,

an inverse to unfold_{νF} is given by the term new_{νF}^{F (νF)} F (unfold_{νF}): F (νF)→νF, which we call fold_{νF}. With these inverse terms we may define another kind of pattern matching — if we write (λ fold_{μF} (x: F (μF)). M), then that will be understood as syntactic sugar for (λy: μF. {unfold_{μF} y/x}M), and similarly for νF (just change the μ’s to ν’s). Unfortunately, when we consider the reduction system which provides the operational semantics for λ^{μν}, we will find that these inverses can not be computed in constant time; instead, they take time proportional to the size of their argument. The impact of this is that it would not be merely syntactic sugar to add a reduction rule such as

(λ fold_{μF} (x: F (μF)). M)(fold_{μF} N) ⟶ {N/x}M,

since it conflates an unknown number of reduction steps into one. This is in contrast to the other pattern matching abbreviations; for example, it makes no essential difference in running time to use the following reduction rules for the conditional statement introduced above:

case true of true. M, false. N ⟶ M case false of true. M, false. N ⟶ N.

One solution to this is to simply add unfold_{μF} and fold_{νF} as constants, with an extra (one step) reduction rule unfold(fold M) ⟶ M for each pair of constants; this will be discussed further below.

3.2 Equational proof system for λ^{μν}

Now that we have introduced the syntax of λ^{μν}, it is time to give a formal semantics for the language, in the form of a set of equational axioms and proof rules very similar to those given for PCF in the previous chapter. The categorical interpretation will continue to be our guide in describing the equations that hold between terms. Thus, the equation Γ▷M = N : σ will be interpreted as saying that the arrows corresponding to the terms Γ ▷ M: σ and Γ ▷ N: σ, which both have source γ and target σ, are equal. We start by listing the usual structural rules necessary to have an equivalence relation that respects term formation, including adding and renaming variables:

(ref ) Γ ▷ M = M : σ

(sym)  \frac{Γ ▷ M = N : σ}{Γ ▷ N = M : σ}

(trans)  \frac{Γ ▷ M = N : σ, Γ ▷ N = P : σ}{Γ ▷ M = P : σ}

(abs)  \frac{Γ, x: σ ▷ M = N : τ}{Γ ▷ (λx: σ. M) = (λx: σ. N) : σ→τ}

(app)  \frac{Γ ▷ M = N : σ→τ, Γ ▷ P = Q : σ}{Γ ▷ MP = NQ : τ}

(add var)  \frac{Γ ▷ M = N : σ}{Γ, x: τ ▷ M = N : σ}

(α) Γ ▷ (λx: σ. M) = (λy: σ. {y/x}M) : σ→τ, if y ∉ FV(M).

The rules (abs) and (app), often referred to as (ξ) and (μ), together with the (→β) axiom below are sufficient to establish that = is a congruence, since we may prove the following substitution lemma:

Lemma 3.2.1 (Substitution) If Γ, x: σ ▷ M = N : τ and Γ ▷ P = Q : σ are provable, then so is Γ ▷ {P/x}M = {Q/x}N : τ.

Proof. Using (abs) on the first equation yields Γ ▷ (λx: σ. M) = (λx: σ. N) : σ→τ; by (app) we may combine this with the second equation to get Γ ▷ (λx: σ. M)P = (λx: σ. N)Q : τ. From (→β) we find that Γ ▷ (λx: σ. M)P = {P/x}M : τ and Γ ▷ (λx: σ. N)Q = {Q/x}N : τ, hence an application of (sym) and two instances of (trans) establish that Γ ▷ {P/x}M = {Q/x}N : τ. (We will not ordinarily go through proofs in such detail; the purpose here was to demonstrate that the rules are sufficient to carry out complete proofs if desired.)

The rest of the axioms and inference rules come in two forms; in terms of the categorical interpretations of the type constructors, the (β) axioms state that the arrows provided for the type make a particular diagram commute, while the (η) axioms and rules establish that those arrows do so uniquely. For example, the categorical definition of the sum states that for any two objects X and Y there is an object X + Y, injection arrows ι_{1}: X→X + Y and ι_{2}: Y →X + Y, and a sum arrow [f, g]: X + Y →Z for every pair of arrows f: X→Z and g: Y →Z. The (β) axioms will assert that these arrows make the following diagram commute:

[figure: Z; f; X; X + Y; ι_{1}; Y; ι_{2}; [f, g]; g] ,

while the (η) axiom says that [f, g] is the unique arrow with this property. Thus, we have the following axioms for +:

(+β_{1}) Γ ▷ [M, N] ∘ ι_{1} = M : σ→υ

(+β_{2}) Γ ▷ [M, N] ∘ ι_{2} = N : τ→υ

(+η) Γ ▷ [M ∘ ι_{1}, M ∘ ι_{2}] = M : σ + τ→υ.

Since 0 is a nullary sum, we only have an (η) rule, which says that □^{υ} is the unique arrow from 0 to υ:

(0η) Γ ▷ □^{υ} = M : 0→υ.

Similarly, the (β) axioms for × assert the commutativity of

[figure: X; X × Y; π_{1}; Y; π_{2}; W; f; ⟨f, g⟩; g] ,

and the (η) axiom says that ⟨f, g⟩ is unique; the (η) axiom for 1 says that ◇ is the unique term of type 1:

(×β_{1}) Γ ▷ π_{1}⟨M, N⟩ = M : σ (×β_{2}) Γ ▷ π_{2}⟨M, N⟩ = N : τ (×η) Γ ▷ ⟨π_{1}M, π_{2}M⟩ = M : σ × τ (1η) Γ ▷ ◇ = M : 1.

The situation for → is somewhat more complex, since the appropriate diagram results not simply from a limit or colimit, but instead from the adjunction between − × Y and Y →−; nevertheless, it is a standard result that the commutativity of

[figure: X × Y; (Y →Z) × Y; curry(f) × id; Z; f; apply]

is expressed by (→β) Γ ▷ (λx: σ. M)N = {N/x}M : τ, while the uniqueness of curry(f) is given by (→η) Γ ▷ (λx: σ. Mx) = M : σ→τ, for x ∉ FV(M).

Recall that we have already described the commutative diagrams corresponding to the inductive and projective types. For μF, the commutativity of

[figure: μF; X; h_{f}; F (μF); F (X); F (h_{f}); φ; f]

is given by (μβ) Γ ▷ (it_{μF}^{τ} M) ∘ fold_{μF} = M ∘ F (it_{μF}^{τ} M) : F (μF)→τ, while the uniqueness of h_{f} is established by

(μη)  \frac{Γ ▷ N ∘ fold_{μF} = M ∘ F (N) : F (μF)→τ}{Γ ▷ N = it_{μF}^{τ} M : μF →τ.}

Dually, the diagram

[figure: F (Y); F (νF); F (k_{g}); Y; νF; k_{g}; g; ψ]

for the projective type νF leads to

(νβ) Γ ▷ unfold_{νF} ∘(new_{νF}^{τ} M) = F (new_{νF}^{τ} M) ∘ M : τ→F (νF)

and

(νη)  \frac{Γ ▷ unfold_{νF} ∘N = F (N) ∘ M : τ→F (νF)}{Γ ▷ N = new_{νF}^{τ} M : τ→νF.}

As promised in the previous section, we may now prove some lemmas about the behavior of our abbreviated terms.

Lemma 3.2.2 Composition is associative, and id is an identity, i.e., M ∘ (N ∘ P) = (M ∘ N) ∘ P and M ∘ id = id ∘M = M.

Proof. Expanding M ∘ (N ∘ P) yields (assuming P has type σ→τ)

(λx: σ. M((λy: σ. N(P y))x)),

which by (→β) is equal to (λx: σ. M(N(P x))); this is also equal to

(λx: σ. (λy: τ. M(Ny))(P x)),

which is the expanded form of (M ∘ N) ∘ P. As for the identity, both of the terms M ∘ id and id ∘M are equal by (→β) to (λx: σ. Mx); using (→η), this is equal to M, since in the definition of ∘ we required that x be a new variable.

Lemma 3.2.3 Application of a “functor” F to a term preserves composition and identities, i.e., F (M ∘N) = F (M) ∘ F (N) and F (id) = id (thus justifying use of the term functor for substitution in a type).

Proof. By induction on the structure of F; we will only show a few of the more interesting cases. For the induction to go through, we actually need to prove more — namely, that this result can be extended to functors with more than one argument, e.g., G(M ∘ N, P ∘ Q) = G(M, P) ∘ G(N, Q); this extension is quite easy and giving the full details would not add enough to the presentation to be worth the extra notation. We assume that Γ ▷ M: τ→υ and Γ ▷ N: σ→τ are well-formed for some Γ.

• if F (t) = G(t) + H(t), then

F (M) ∘ F (N) = [F (M) ∘ F (N) ∘ ι_{1}, F (M) ∘ F (N) ∘ ι_{2}]
= [F (M) ∘ ι_{1} ∘ G(N), F (M) ∘ ι_{2} ∘ H(N)]
= [ι_{1} ∘ G(M) ∘ G(N), ι_{2} ∘ H(M) ∘ H(N)]
= [ι_{1} ∘ G(M ∘ N), ι_{2} ∘ H(M ∘ N)]
= F (M ∘ N);

also, F (id^{σ}) = [ι_{1}, ι_{2}] = id^{F (σ)}.

• if F (t) = G(t)→H(t), then

F (M ∘ N) = λf: F (σ). H(M ∘ N) ∘ f ∘ G((M ∘ N)^{op})
= λf: F (σ). H(M) ∘ H(N) ∘ f ∘ G(N^{op}) ∘ G(M^{op})
= λf: F (σ). H(M) ∘ (F (N)f) ∘ G(M^{op})
= λf: F (σ). F (M)(F (N)f)
= F (M) ∘ F (N);

for the identity, we have

F (id^{σ}) = λf: F (σ). H(id^{σ}) ∘ f ∘ G((id^{σ})^{op})
= λf: F (σ). id^{H(σ)} ∘f ∘ id^{G(σ)}
= id^{F (σ)} .

• if F (t) = μs. G(s, t), then

F (M) ∘ F (N) ∘ fold_{F (σ)}
= F (M) ∘ fold_{F (τ)} ∘G(F (τ), N) ∘ G(F (N), σ)
= fold_{F (υ)} ∘G(F (υ), M) ∘ G(F (M), τ) ∘ G(F (τ), N) ∘ G(F (N), σ)
= fold_{F (υ)} ∘G(F (υ), M) ∘ G(F (υ), N) ∘ G(F (M), σ) ∘ G(F (N), σ)
= fold_{F (υ)} ∘G(F (υ), M ∘ N) ∘ G(F (M) ∘ F (N), σ),

where the interchange G(F (M), τ) ∘ G(F (τ), N) = G(F (υ), N) ∘ G(F (M), σ) in the middle is possible because both sides are equal to G(F (M), N), noticing that, e.g., G(F (M), τ) = G(F (M), id^{F (τ)}) and using the multiple argument form of the induction hypothesis. From the above we may then use (μη) to deduce that F (M) ∘ F (N) = it_{F (σ)}^{F (υ)}(fold_{F (υ)} ∘G(F (υ), M ∘ N)) = F (M ∘ N). For the identity, we

must show that F (id^{σ}) = it_{F (σ)}^{F (σ)} fold_{F (σ)} is the identity; but id^{F (σ)} ∘ fold_{F (σ)} = fold_{F (σ)} ∘G(id^{F (σ)}, σ)

by the induction hypothesis, so id^{F (σ)} = it_{F (σ)}^{F (σ)} fold_{F (σ)} by (μη).

We may now use this lemma about functors to prove that the defined terms for unfold_{μF} and fold_{νF} are really inverses.

Lemma 3.2.4 The term unfold_{μF} ≡ it_{μF}^{F (μF)} F (fold_{μF}) is an inverse for fold_{μF}, i.e., fold_{μF} ∘ unfold_{μF} =

id^{μF} and unfold_{μF} ∘ fold_{μF} = id^{F (μF)}. Likewise, fold_{νF} ≡ new_{νF}^{F (νF)} F (unfold_{νF}) is an inverse for unfold_{νF}.

Proof. For variety, we will show the proof for the projective type νF; the inductive case is quite similar. First, note that unfold_{νF} ∘ fold_{νF} = F (fold_{νF}) ∘ F (unfold_{νF}) = F (fold_{νF} ∘ unfold_{νF}) by (νβ) and the previous lemma; thus we only need to show the direction fold_{νF} ∘ unfold_{νF} = id^{νF}. From what we have just shown, we know that unfold_{νF} ∘ fold_{νF} ∘ unfold_{νF} = F (fold_{νF} ∘ unfold_{νF}) ∘ unfold_{νF}, hence the (νη) rule allows us to derive fold_{νF} ∘ unfold_{νF} = new_{νF}^{νF} unfold_{νF}. This last term is the identity, by using (νη) on the equation unfold_{νF} ∘ id^{νF} = F (id^{νF}) ∘ unfold_{νF}, so we are done.

3.3 The reduction system λ_{r}^{μν}

In this section we present an operational semantics for λ^{μν}, in the form of a set of reduction rules similar to those given for PCF in the previous chapter. We will show that this system is confluent and strongly normalizing, hence it will be meaningful to speak of the (unique) result of evaluating a term by reducing it to normal form. We then study the set of definable functions and find that this set of functions properly includes those that may be proven total in Peano arithmetic, hence we have a system which is more expressive than Gödel’s System T of primitive recursive functionals.

The reduction rules we will take for λ_{r}^{μν} are essentially the (β) axioms of the previous section, oriented in the direction of “computation.” Since we do not include any (η) rules, the form of some of the axioms will be changed to better match our notion of normal form — instead of dealing with functional terms and composition, we will apply such terms to dummy arguments to get rid of the ∘’s. Here are the reduction rules:

(+β_{1})_{r} [M, N](ι_{1}P) ⟶ MP

(+β_{2})_{r} [M, N](ι_{2}P) ⟶ NP

(×β_{1})_{r} π_{1}⟨M, N⟩ ⟶ M

(×β_{2})_{r} π_{2}⟨M, N⟩ ⟶ N

(→β)_{r} (λx: σ. M)N ⟶ {N/x}M

(μβ)_{r} it_{μF}^{τ} M(fold_{μF} P) ⟶ M(F (it_{μF}^{τ} M)P)

(νβ)_{r} unfold_{νF} (new_{νF}^{τ} MP) ⟶ F (new_{νF}^{τ} M)(MP).

As usual, we write M ⟶ N if there is some subterm P of M (i.e., M ≡ C[P] for some context C[ ]) and substitution θ such that P ≡ θL and N ≡ C[θR], where L ⟶ R is one of the above rules. The subterm P in M which is replaced is the redex, the term θR which replaces it is the contractum, and the result N is the reduct. A term which contains no redexes is a normal form. We write ⟶ for the reflexive transitive closure of ⟶; if we only want the transitive closure, which means that we must perform at least one reduction step, then we write ⟶^{+}. Note that, in this section, we will use ≡ to mean α-equivalent, rather than strictly identical — two different reductions from a given term may result in different names for “corresponding” bound variables, so for confluence we need to be able to rename them; however, using (α) as a reduction rule is a bad idea, since it would need special handling to preserve strong normalization (it does not have the same intuitive feeling of “performing a computation step” as the (β) rules, either).

We have left off the types and typing contexts in defining reduction, but it is an easy lemma to prove that reduction preserves type: Lemma 3.3.1 (Subject Reduction) If Γ ▷ M: σ is well-formed and M ⟶ N, then Γ ▷ N: σ is also well-formed.

The first important theorems of this section are that λ_{r}^{μν} is confluent and strongly normalizing. As a result, we will be able to speak of the unique normal form λ_{r}^{μν}(M) of an arbitrary term M, independent of any specific reduction strategy — one strategy may be more efficient than another at finding the normal form of a given term, but every reduction path will eventually terminate with the same result. We will prove strong normalization first, as this result is used in the proof of confluence.

Theorem 3.3.2 (Strong Normalization) There is no infinite sequence of reductions M_{1} ⟶ M_{2} ⟶ M_{3} ⟶ · · ·.

Proof. In section 3.5 we give a translation of λ^{μν} into Girard’s System F, with the property that if M ⟶ N in λ_{r}^{μν} then \overline{M} ⟶^{+} \overline{N} in F; since F is strongly normalizing [17], this proves that λ_{r}^{μν} is also, since otherwise we would be able to construct the infinite reduction sequence \overline{M_{1}} ⟶^{+} \overline{M_{2}} ⟶^{+} \overline{M_{3}} ⟶^{+} ⋯ in F.

Theorem 3.3.3 (Confluence) If M ⟶ N and M ⟶ P, then there is a term Q such that N ⟶ Q and P ⟶ Q.

Proof. We only need to show that λ_{r}^{μν} is weakly confluent, i.e., if M ⟶ N and M ⟶ P then N and P have a common reduct, since by the previous theorem λ_{r}^{μν} is strongly normalizing — using Newman’s theorem [39] we may conclude that it is confluent. It is easy to see that it is weakly confluent, since there are no critical pairs, hence we are done.

To continue the comparison of λ_{r}^{μν} with PCF, we need to establish which types are observable. The criterion we use for whether a type is observable is if provable equality of closed terms of that type may be decided by reducing the terms to normal form and checking for syntactic identity. We restrict ourselves to closed terms because free variables can block the application of reduction rules — for example, the equation x: σ ×τ ▷⟨π_{1}x, π_{2}x⟩ = x : σ ×τ is true, but the two sides are distinct normal forms. If σ and τ are observable types, then we will see below that any closed term which could be substituted for x will be reducible to a pair ⟨N_{1}, N_{2}⟩ of normal forms, whence the left-hand side will reduce by two additional (×β) steps to a term identical to the right-hand side; however, substituting every possible closed term for x and reducing is not a very effective way to try to observe equality.^{2} Functional types will not be observable, since a λ-abstraction introduces a variable which may cause the above problems in the body of the abstraction. Therefore, let us consider the possible normal forms which do not contain any free variables or λ-abstractions. In addition, although we have other ways than λ-abstraction to create terms of functional type, we will not want to try to observe a normal form containing such a subterm unless it is at the head of an application, thus guaranteeing that the term is not equal to another normal form with a λ-abstraction in that position.

Lemma 3.3.4 The closed normal forms that do not contain any subterms of function type except at the head of an application are those well-formed terms that may be generated by the following grammar:

R ::= ◇ | ι_{1}R | ι_{2}R | ⟨R, R′⟩ | fold_{μF} R;

we refer to these terms as results.

Proof. We could not have a result of the form π_{1}R, for example, because for it to be a normal form we would need R to be a result of product type which is not a pair. Similarly, we could not have a result of the form π_{2}R, it_{μF} RR′, unfold_{νF} R, or [R, R′]R′′. The only other way to get a result of type σ that is not of the form above is by □^{σ}R, where R has type 0. There are no closed terms of type 0, so this is impossible. Finally, note that there are no closed normal forms of type νF without functional subterms, since normal forms of that type would have to be of the form new_{νF} RR′, where R has a functional type. Therefore, the observable types are 1, σ + τ, σ × τ, and μF, where σ and τ are observable and F (υ) is observable whenever υ is. The definition of a result as a closed normal form of observable type then matches the characterization given above.

Some examples of observable types are:

• bool ≡ 1 + 1, the type of booleans introduced above; the results are true ≡ ι_{1}◇ and false ≡ ι_{2}◇.

• nat ≡ μt. 1 + t, the set of natural numbers; results of this type take the form zero ≡ fold(ι_{1}◇) or succ(n) ≡ fold(ι_{2}n), where n is another such result.

• bool × nat, pairs ⟨b, n⟩ of booleans and naturals.

• natlist ≡ μt. 1 + nat × t, the type of lists of natural numbers; the results of this type are of the form nil ≡ fold(ι_{1}◇) and cons(n, ℓ) ≡ fold(ι_{2}⟨n, ℓ⟩).

Thus we regain many of the observable types of PCF as a consequence of our more general definition.

We may now state the final theorem of this section, which asserts that λ_{r}^{μν} is adequate for the computation of results of programs. This is analogous to the result property for PCF, although the method of proof will be somewhat different. Because of the form of the (η) rules for inductive and projective types, we do not have a reasonable definition for either η-reduction or η-expansion. For example, not only would use of the rule M ⟶ it_{μF}^{τ} N be conditional on having proven the equation M ∘ fold_{μF} = N ∘ F (M), but it also introduces the term N in the contractum which does not occur in the redex — since N could contain free variables not present in M, we would need to reintroduce typing contexts to insure subject reduction. The same observation holds for the opposite direction, it_{μF}^{τ} N ⟶ M; therefore, we will not be able to proceed through the intermediate step of an η-postponement lemma.

2And not necessarily even valid — this is the (ω) rule, which Plotkin [41] showed is not always sufficient for extensionality.

Theorem 3.3.5 If ∅ ▷ P = R : σ is provable for R a result, then P ⟶ R in λ_{r}^{μν}.

Proof. It is sufficient to show that if ∅▷P =^{η}_{1} Q: σ is provable, and Q ⟶ R for R a result, then P ⟶ R, where =^{η}_{1} means that exactly one (η) rule is used (along with whatever structural rules are needed). The theorem then follows by the normal form property of ⟶ and induction on the number of (η) rules.

The problem then is to construct a reduction sequence P ⟶ R from the given sequence Q ⟶ R. If the (η) rule is (+η), (×η), or (→η), then this chiefly consists of mimicking the reduction from Q on P, either adding or deleting steps corresponding to the destruction of an (η) redex by a (β) reduction. One difficulty arises in these cases from the non-linearity of (+η) and (×η) — if Q contains the subterm [M ∘ ι_{1}, M ∘ ι_{2}] where P only has M, for example, then we must choose to follow the reduction on only the first, say, of the two components of the choice in reducing P; since R is a result and reduction is confluent, we may make this choice arbitrarily.

We are thus left with the case of the (η) step for one of the recursive types. We will consider (μη) — the situation for (νη) is entirely similar. If P contains a subterm M and Q contains it_{μF}^{τ} N in the same position, then in constructing the reduction from P we will need to use the hypothesis from the (η) rule, i.e., M ∘fold_{μF} = N ∘F (M). Now, for every (μβ) step in the original reduction of the form it_{μF}^{τ} N′(fold_{μF} K) ⟶ N′(F (it_{μF}^{τ} N′)K), we must replace it with the equational step M′(fold_{μF} K) = N′(F (M′)K), where M′ and N′ are corresponding residuals of M and N. We must then go back and apply the current theorem to convert this new equational proof of P = R into a reduction P ⟶ R; we avoid circularity by noting that the height of the new proof tree for P = R is shorter than before, measured in the number of nested applications of the (μη) and (νη) rules. In the situation where P contains it_{μF}^{τ} N and Q contains M we go through the same process, with the additional requirement that the reduction from Q must be rearranged so that if M is a λ-abstraction it will only be β-reduced when applied to arguments of the form fold_{μF} K.

Corollary 3.3.6 If ∅ ▷ P = Q : σ is provable at observable type σ, then λ_{r}^{μν}(P) ≡ λ_{r}^{μν}(Q).

Proof. Trivial, since reduction is confluent and strongly normalizing. If we define observational congruence again as Γ▷M ≃ N: σ if λ_{r}^{μν}(P[M]) ≡ λ_{r}^{μν}(P[N]) for every well-formed program context P[ ], then we find that the full equational proof system, including the extensional rules, is sound for reasoning about programs:

Corollary 3.3.7 The equational proof system for λ^{μν} is sound for ≃.

Proof. Follows directly from the previous corollary. Therefore, we conclude that λ_{r}^{μν} provides a suitable operational semantics for the language λ^{μν}.

3.4 Comparison with System T

The question naturally arises of what functions are expressible in λ^{μν}. We speak here of functions on the natural numbers, as given by the (observable) type nat described in the previous section. Since λ_{r}^{μν} is strongly normalizing, all the functions must be total. We can enumerate the terms of λ^{μν}, therefore we must not be able to represent all of the total functions (since that set is not recursively enumerable). In this section we will see that all of the functions that are provably total in Peano arithmetic are definable, as well as some that are not. In the next section we show that λ_{r}^{μν} is strongly normalizing by simulating it in System F; since the functions expressible in F are exactly those which are provably total in second-order arithmetic, we thus have a range in which the answer must fall:

Theorem 3.4.1 The class of functions definable in λ^{μν} properly includes those which are provably total in Peano arithmetic, and is included in the class of functions provably total in second-order arithmetic.

To prove the first part of this theorem, we will compare λ^{μν} to Gödel’s System T of primitive recursive functionals of finite type ([18]; see also [17], for example). It is well-known that the natural number functions representable in T are precisely the partial recursive functions that are provably total in Peano arithmetic. Therefore, we start by showing that all those functions are also representable in λ^{μν}.

System T consists of the simply-typed lambda calculus λ^{→} plus the following constant terms and equations:

0: nat

succ: nat→nat

R^{τ}: τ→(τ→nat→τ)→nat→τ

R^{τ} MN0 = M

R^{τ} MN(succ P) = N(R^{τ} MNP)P.

Here the type identifier nat is a new type constant, whose interpretation is the set of natural numbers; the terms 0 and succ represent the natural number zero and the successor function. The term R gives a recursor; it is a generalization of definition by primitive recursion — if a function f: \overline{nat}→nat→nat is defined using primitive recursion as

\begin{matrix}f(x̄)(0) = g(x̄) \\ f(x̄)(succ n) = h(x̄)(f(x̄)(n))(n), \end{matrix}

where g: \overline{nat}→nat and h: \overline{nat}→nat→nat→nat are given functions, then f may be defined using R as (λx̄: σ̄. R^{nat}(gx̄)(hx̄)). The type τ in R^{τ} may be any type, not just nat, hence we are able to define primitive recursive functionals. The well-known non-primitive recursive function, Ackermann’s function^{3}, specified by

Ack(0)(y) = succ y

Ack(succ x)(0) = Ack(x)(1)

Ack(succ x)(succ y) = Ack(x)(Ack(succ x)(y)),

is easily defined with R as

R^{nat→nat}(succ)(λf: nat→nat. λx: nat. R^{nat}(f1)(λz: nat. λy: nat. fz)).

The variable f in the second argument is bound to the curried function Ack(x) for the appropriate current value of x each time the outer recursion is unfolded; this is not possible in the ordinary scheme of primitive recursive function definition.

We have already seen how to define a type nat with constants 0 and succ in λ^{μν}; thus we only need to define a recursor R^{τ} and show that it satisfies the above equations. The syntax of λ^{μν} only gives us an iterator, i.e., a term Z^{τ}: τ→(τ→τ)→nat→τ satisfying

\begin{matrix}Z^{τ} MN 0 = M \\ Z^{τ} MN(succ P) = N(Z^{τ} MNP). \end{matrix}

Here we use the compound Z^{τ} MN as an abbreviation for the term it_{nat}^{τ}[λ◇. M, N]. Note that the argument P is not available to the function N in the recursive step, unlike the case for the recursor. The second argument to N is not used very often; for example, we may write the Ackermann function using Z as

Z^{nat→nat}(succ)(λf: nat→nat. Z^{nat}(f1)f).

3Actually due to Péter; Ackermann’s original function was somewhat different; see [47] for example.

One significant function which does use the second argument is predecessor:

pred = R^{nat} 0(λx: nat. λy: nat. y).

In a language with products, a standard way to imitate a recursor with an iterator is to have the iterative call return both the current result and the corresponding value of the unavailable second argument. That is,

Z^{τ×nat} M′N′0 = ⟨M, 0⟩
Z^{τ×nat} M′N′(succ P) = (let ⟨x: τ, p: nat⟩ = (Z^{τ×nat} M′N′P) in ⟨Nxp, succ p⟩),

where we must take M′ ≡ ⟨M, 0⟩ and N′ ≡ (λ⟨x: τ, p: nat⟩. ⟨Nxp, succ p⟩). Thus the recursor-defined function R^{τ} MN is also given by π_{1} ∘ (Z^{τ×nat} M′N′).

Using this replacement for the recursor has an embarrassing property when applied to the definition of the predecessor — the equation pred(succ P) = P only holds if P is equal to a numeral succ^{n} 0. Even worse, in terms of the reduction system, pred must first evaluate its argument to normal form (which is wasteful if, for example, we are only going to test whether the predecessor is zero), and then, to compute pred(succ^{n+1} 0), it will apply the successor function to zero n times to reconstruct succ^{n} 0, instead of just peeling off the outermost succ. Thus predecessor has been turned from a constant time lazy operation into a linear time strict operation.^{4}

Our solution to this problem was hinted at earlier — we introduce the constant unfold_{μF}: μF →F (μF), and add the axioms

(μβ′) Γ ▷ unfold_{μF} ∘ fold_{μF} = id^{F (μF)} : F (μF)→F (μF)

and

(μη′) Γ ▷ fold_{μF} ∘ unfold_{μF} = id^{μF} : μF →μF.

Using the (μη) rule, we proved in lemma 3.2.4 that this new constant is equal to the term it_{μF}^{F (μF)} F (fold_{μF}), which we have also been calling unfold_{μF}. To λ_{r}^{μν} we add the corresponding β-reduction

(μβ′)_{r} unfold_{μF} (fold_{μF} P) ⟶ P;

it is not difficult to prove that all the theorems of the previous section continue to hold for this expanded system. Of course, because these new constants are definable in the unexpanded language, we are not changing the set of definable functions, only the set of expressible algorithms.

Dually, we also add a constant fold_{νF}: F (νF)→νF and rules

(νβ′) Γ ▷ unfold_{νF} ∘ fold_{νF} = id^{F (νF)} : F (νF)→F (νF)

(νη′) Γ ▷ fold_{νF} ∘ unfold_{νF} = id^{νF} : νF →νF

(νβ′)_{r} unfold_{νF} (fold_{νF} P) ⟶ P;

this avoids a similar problem for projective types.

For example, let us define a type bstr ≡ νt. bool × t of boolean streams, with destructors head ≡ π_{1} ∘ unfold_{bstr}: bstr→bool and tail ≡ π_{2} ∘ unfold_{bstr}: bstr→bstr, plus a constructor all ≡ new_{bstr}^{bool} dup: bool→bstr which creates a constant stream, where dup ≡ (λb: bool. ⟨b, b⟩): bool→bool × bool. Then we find that head(all false) ⟶ false and tail(all false) ⟶ all false, as expected. To define a constructor which will cons a boolean onto the head of a stream, we may use cons ≡ new_{bstr}^{bool×bstr}(id^{bool} × unfold_{bstr}): bool × bstr→bstr.

4The lazy versus strict distinction will be important in the next chapter, where we allow non-termination.

Unfortunately, this introduces an unnecessary unfolding when evaluating tail(cons⟨true, all false⟩), for example; the normal form of this term is cons⟨false, all false⟩ instead of simply all false. This is not entirely unexpected, since bstr is not an observable type, hence there may be many distinct normal forms for a given stream. What is worse is that this extra unfolding will propagate through an entire sequence of cons’s, i.e., to compute the tail of a stream b_{1} : : b_{2} : : …: : b_{n} : : s, where we write b : : s as shorthand for cons⟨b, s⟩, the reduction will pick off b_{1} through b_{n}, unfold s once, and then cons b_{2} through b_{n} back onto the head! The solution is to use the constant fold_{bstr}: bool × bstr→bstr instead of cons; the extra unfolding is avoided, and the tail can be computed in constant time.

With unfold_{μF} we may make an ad hoc definition of predecessor simply as pred = [λ◇. 0, id] ∘ unfold_{nat}. A more interesting discovery is that we may use this predecessor function to define a recursor R_{it} with the same reduction behavior as R. The idea is to use the iterator to create a function that passes the needed second argument down from the outside, rather than creating it up from the inside. Here is the term that defines R_{it}^{τ} MN:

(λn: nat. Z^{nat→τ} (λx: nat. M)(λf: nat→τ. λm: nat. N(f(pred m))(pred m))nn).

Theorem 3.4.2 A function defined with the recursor R_{it} will have the same running time in λ_{r}^{μν} + (μβ′)_{r} (within a constant factor) as the equivalent function defined with R will have in T.

Proof. All we need to show is that the two reduction rules for R in T can be performed in constant time in λ_{r}^{μν} + (μβ′)_{r}. We omit a number of steps showing the details of reducing Z and pred; it is easy to verify that the total number of steps remains independent of the size of the input. Also, we abbreviate the term Z^{nat→τ} (λx: nat. M)(λf: nat→τ. λm: nat. N(f(pred m))(pred m)) as Q_{M,N}^{τ}.

R_{it}^{τ} MN 0 ⟶ Q_{M,N}^{τ} 0 0
⟶ (λx: nat. M) 0
⟶ M
R_{it}^{τ} MN(succ P) ⟶ Q_{M,N}^{τ}(succ P)(succ P)
⟶ (λf: nat→τ. λm: nat. N(f(pred m))(pred m))(Q_{M,N}^{τ} P)
(succ P)
⟶ (λm: nat. N(Q_{M,N}^{τ} P (pred m))(pred m))(succ P)
⟶ N(Q_{M,N}^{τ} P (pred(succ P)))(pred(succ P))
⟶ N(Q_{M,N}^{τ} P P)P.

This last term is one (→β) step from N(R_{it}^{τ} MNP)P, which corresponds to the term we would get after one reduction step from R^{τ} MN(succ P) in T.

We have already mentioned the relation between System T and the functions that are provably total in Peano arithmetic. Another characterization of the functions expressible in T is that they are the functions definable by transfinite recursion up to some ordinal α < ϵ_{0}, where ϵ_{0} is the least ordinal ϵ such that ϵ = ω^{ϵ} (see [30] or [48]; a good text covering this subject is [47]). We will show that λ^{μν} is more expressive than T, thus completing the proof of Theorem 3.4.1, by constructing the Hardy function H_{ϵ_{0}}, which requires recursion up to ϵ_{0} itself [8]. The method we use to represent ordinal numbers and construct the hierarchy of Hardy functions is based on an example given by Coquand and Paulin [11].

To define H_{α} for α ≤ ϵ_{0} we will need to choose a fundamental sequence for each limit ordinal ≤ ϵ_{0}; that is, for each limit ordinal λ we need an increasing, natural number indexed sequence ⟨λ[0], λ[1], …⟩ of ordinals less than λ whose limit is λ. A convenient choice makes use of the Cantor normal form, which writes each ordinal α < ϵ_{0} uniquely as ω^{α_{1}} + ⋯ + ω^{α_{k}} + m, for some natural numbers k and m and ordinals (themselves in normal form) 0 < α_{k} ≤ … ≤ α_{1} < α. If α is a limit ordinal, then we take the ordinal ω^{α_{1}} + ⋯ + ω^{α_{k}}[n] as the nth element of the fundamental sequence for α, where ω^{β+1}[n] = ω^{β} · n and ω^{λ}[n] = ω^{λ[n]} for λ a limit. We extend this definition to ϵ_{0} by taking ϵ_{0}[0] = 1 and ϵ_{0}[n + 1] = ω^{ϵ_{0}[n]}. Now we may define the functions H_{α} as follows:

H_{0}(n) = n
H_{α+1}(n) = H_{α}(n + 1)
H_{λ}(n) = H_{λ[n]}(n).

The type of notations for countable ordinals may be specified as the inductive type ord ≡ μt. 1 + t + (nat→t); the constructors are thus

ordzero ≡ fold_{ord} ∘ι_{1}^{3}: 1→ord
ordsucc ≡ fold_{ord} ∘ι_{2}^{3}: ord→ord
lim ≡ fold_{ord} ∘ι_{3}^{3}: (nat→ord)→ord.

The interpretation of lim is that it creates an ordinal given a function which specifies the fundamental sequence for the ordinal; for example, we may define ω ≡ lim inord, where inord ≡ it_{nat}^{ord}[ordzero, ordsucc] is the natural injection from nat to ord, since ⟨0, 1, 2, …⟩ is the fundamental sequence for ω. Addition, multiplication, and exponentiation of ordinals may be defined as follows:

ordplus ≡ (λα: ord. it_{ord}^{ord}[(λ◇. α), ordsucc, lim])

ordtimes ≡ (λα: ord. it_{ord}^{ord}[ordzero, (λβ: ord. ordplus βα), lim])
ordexp ≡ (λα: ord. it_{ord}^{ord}[ordone, (λβ: ord. ordtimes βα), lim]),

where ordone ≡ ordsucc ∘ ordzero. A function that creates an exponential stack of n ω’s when applied to a natural number n is omegaexp ≡ it_{nat}^{ord}[ordone, ordexp ω]; we may thus define a notation for ϵ_{0} by stating ϵ_{0} ≡ lim omegaexp.

The following term represents the Hardy function H: ord→nat→nat in λ^{μν}:

it_{ord}^{nat→nat}[(λ◇. id^{nat}), (λf: nat→nat. f ∘ succ), (λg: nat→nat→nat. λn: nat. gnn)].

We will demonstrate the use of these definitions by evaluating H_{ϵ_{0}}(0):

Hϵ_{0} 0 ≡ H(lim omegaexp) 0
⟶ (H ∘ omegaexp) 0 0
⟶ H(ordone◇) 0
≡ H(ordsucc(ordzero◇)) 0
⟶ ((H(ordzero◇)) ∘ succ) 0
⟶ (id^{nat} ∘ succ) 0
⟶ succ 0.

Being able to construct H_{ϵ_{0}} is sufficient for showing that λ^{μν} can express more than the primitive recursive functionals of T, but there is no reason to stop at ϵ_{0}. Indeed, since we may define the Veblen hierarchy of functions φ_{α}: ord→ord for all α: ord, we have a system of notation for all the ordinals less than Γ_{0}, the first “strongly critical” ordinal (see [15] for a very readable discussion of the significance of Γ_{0}). The particular Veblen hierarchy to which we refer is that starting from φ_{0}(β) = ω^{β}; then the function φ_{α} for α > 0 enumerates the common fixed points of all the functions φ_{γ} for γ < α. For example, φ_{1} enumerates the fixed points of φ_{0} = λβ. ω^{β}; these are known as the epsilon numbers, and indeed the first fixed point φ_{1}(0) is the ordinal ϵ_{0} discussed above. We will not give the term which computes φ here, but a detailed description of how to define it in terms of fundamental sequences is given in [10].

The ordinal Γ_{0} is still not the largest ordinal we can express in λ^{μν}. As Miller shows in [34], we may extend the definition of φ_{α} to uncountable ordinals α that satisfy certain conditions. For example, φ_{Ω} is the function which enumerates the strongly critical ordinals (so φ_{Ω}(0) = Γ_{0}), where Ω is the least uncountable ordinal. We can express Ω, and many other uncountable ordinals, in λ^{μν} by introducing the type ord_{1} ≡ μt. 1 + t + (nat→t) + (ord→t). As for ord, the first three components of the body of the recursive type represent zero, successor ordinals, and (nat-indexed) limit ordinals. But ord_{1} also has a fourth component which allows ord-indexed limits. If we define lim_{1}^{1} ≡ fold_{ord_{1}} ∘ι_{4}^{4}: (ord→ord_{1})→ord_{1}, and make the obvious definition for inord_{1}: ord→ord_{1}, then we may set Ω ≡ lim_{1}^{1} inord_{1}. We may then define the usual arithmetic operations on ord_{1}, allowing the construction of such ordinals as Ω^{2}, Ω^{Ω}, and even ϵ_{Ω+1} = Ω^{Ω^{···}}, with which we may go back and construct the countable (but very large) ordinal φ_{ϵ_{Ω+1}+1}(0), known as “Howard’s ordinal.”^{5}

We may make one more step in the production of ever-larger ordinals. By generalizing the construction of the types ord and ord_{1}, we may construct the class ord_{n} of abstract tree ordinals (see [56]), all of which will have cardinality ℵ_{n}, by the inductive type μt. 1 + t + (nat→t) + (ord→t) + (ord_{1}→t) + ⋯ + (ord_{n−1}→t). Elements of this type may be defined as limits of order type up to Ω_{n}, the nth regular ordinal beyond Ω_{0} ≡ ω. Further discussion of these ordinals is far beyond the scope of this dissertation; for more details see for example [34, 56].

3.5 Comparison with System F

In this section we will give a translation of λ^{μν} into Girard’s System F that will allow us to prove the strong normalization of λ_{r}^{μν} from that of F. The essential part of this translation is the well-known representation of finite sums and products and initial and terminal fixed points in F (see for example [17] or [24]), although the details of the translation for inductive and projective types are original. We have already noted that the functions expressible in F are precisely those that are provably total in second order arithmetic, so the fact that all the functions computable by λ_{r}^{μν} are also computable in F gives us an upper limit on the expressibility of λ^{μν}. We suspect that the inclusion is proper, although we do not know an example of a function computable in F and not in λ_{r}^{μν}. Interestingly, there are algorithms computable in λ_{r}^{μν} + (μβ′)_{r} which are not computable in F — the simplest example is the constant time predecessor mentioned in the previous section. This is a symptom of a more general lack in System F, namely, that types such as products, sums, and least fixed points are not extensional; as a result, many desirable equations between terms are not provable.

System F, which was discovered independently by Girard [16] and Reynolds [46], extends the simply typed lambda calculus λ^{→} with type variables and the polymorphic type ∀t. σ. Formally, we add the following term formation rules:

(∀ Intro)  \frac{Γ ▷ M: σ}{Γ ▷ (Λt. M): ∀t. σ} for t not free in Γ

(∀ Elim)  \frac{Γ ▷ M: ∀t. σ}{Γ ▷ Mτ: \{τ/t\}σ.}

The metavariables σ and τ now refer to arbitrary type expressions formed with → and ∀; that is, they may contain free type variables. The type abstraction operator Λ binds type variables in its body in the same manner as λ binds regular variables, thus we need equational rules for Λ analogous to those for λ:

(∀ abs)  \frac{Γ ▷ M = N : σ}{Γ ▷ (Λt. M) = (Λt. N) : ∀t. σ}

5No relation.

\begin{matrix}M: σ & \overline{M}: \overline{σ} \\ x: σ & x: \overline{σ} \\ (λx: σ. M): σ→τ & (λx: \overline{σ}. \overline{M}): \overline{σ}→\overline{τ} \\ MN: τ & \overline{M} \overline{N}: \overline{τ} \\ ι_{1}: σ→σ + τ & (λx: \overline{σ}. Λt. λf: \overline{σ}→t. λg: \overline{τ}→t. fx): \overline{σ}→\overline{σ + τ} \\ ι_{2}: τ→σ + τ & (λx: \overline{τ}. Λt. λf: \overline{σ}→t. λg: \overline{τ}→t. gx): \overline{τ}→\overline{σ + τ} \\ [M, N]: σ + τ→υ & (λx: \overline{σ + τ}. x\overline{υ} \overline{M} \overline{N}): \overline{σ + τ}→\overline{υ} \\ □^{υ}: 0→υ & (λx: \overline{0}. x\overline{υ}): \overline{0}→\overline{υ} \\ π_{1}: σ × τ→σ & (λx: \overline{σ × τ}. x\overline{σ}(λy: \overline{σ}. λz: \overline{τ}. y)): \overline{σ × τ}→\overline{σ} \\ π_{2}: σ × τ→τ & (λx: \overline{σ × τ}. x\overline{τ}(λy: \overline{σ}. λz: \overline{τ}. z)): \overline{σ × τ}→\overline{τ} \\ ⟨M, N⟩: σ × τ & (Λt. λf: \overline{σ}→\overline{τ}→t. f\overline{M} \overline{N}): \overline{σ × τ} \\ ◇: 1 & (Λt. λx: t. x): \overline{1} \end{matrix}

Table 3.1: Translation of function, sum, and product terms

(∀ app)  \frac{Γ ▷ M = N : ∀t. σ}{Γ ▷ Mτ = Nτ : \{τ/t\}σ}

(∀α) Γ ▷ (Λt. M) = (Λs. {s/t}M) : ∀t. σ, if s not free in M

(∀β) Γ ▷ (Λt. M)τ = {τ/t}M : {τ/t}σ

(∀η) Γ ▷ (Λt. Mt) = M : ∀t. σ, for t not free in M.

As usual, the reduction relation obtained by directing the (→β) and (∀β) axioms from left to right will be denoted ⟶; if a term M reduces to another term N in one or more steps, then we write M ⟶^{+} N.

We will now start to give a translation from λ^{μν} into F, such that if Γ ▷ M: σ is a well-formed term in λ^{μν}, then \overline{Γ} ▷ \overline{M}: \overline{σ} is a well-formed term of F. Type and term variables will stay the same under translation, as will lambda abstraction and application. The translation of the binary sum type σ + τ will be ∀t. (\overline{σ}→t)→(\overline{τ}→t)→t, where t is not free in \overline{σ} or \overline{τ}; the empty type 0 is represented by ∀t. t. Dually, the binary product σ × τ translates to ∀t. (\overline{σ}→\overline{τ}→t)→t, while the singleton type 1 becomes ∀t. t→t. The translation of terms for these types is given in Table 3.1, where of course it is understood that all of the variables introduced on the right hand side are new.

Before we give the translation for the inductive and projective types, we will need a few abbreviations. It will be convenient to continue our practice of treating a type expression σ as a functor with respect to substitution for a type variable t, thus we will write \overline{F} (\overline{τ}) to mean \{\overline{τ}/t\}\overline{σ}; it is an easy exercise to show that \overline{F (τ)} ≡ \overline{F} (\overline{τ}). Similarly, if M is a term of type τ→υ, then we write \overline{F} (\overline{M}) for the term \overline{F (M)} of type \overline{F (τ)}→\overline{F (υ)}. The “functor” \overline{F} will no longer preserve composition or identities, since most types under the translation into F are no longer extensional (see below), but it will suffice for the purposes of this section because we are only interested in showing that the β reductions of λ^{μν} are strongly normalizing.

We will also need the existentially quantified type ∃t. σ. This may be expressed in terms of ∀ and → as ∀s. (∀t. σ→s)→s, where s is a fresh type variable. A term of the existential type ∃t. σ is like a pair ⟨τ, M⟩ of a type τ and a term M of type {τ/t}σ; we will exploit this analogy by introducing (as in [17]) the syntactic sugar

⟨τ, N⟩ ≡ (Λs. λx: ∀t. σ→s. xτN): ∃t. σ

M: σ  \overline{M}: \overline{σ}
fold_{μF}  (λx: \overline{F} (\overline{μF}). Λt. λf: \overline{F} (t)→t. f(\overline{F} (\overline{it} t f) x)): \overline{F} (\overline{μF})→\overline{μF}
it_{μF}^{τ}  \overline{it} \overline{τ} ≡ (Λs. λf: \overline{F} (s)→s. λx: \overline{μF} . x s f)\overline{τ}: (\overline{F} (\overline{τ})→\overline{τ})→\overline{μF} →\overline{τ}
unfold_{νF} (λ⟨t, ⟨f: t→\overline{σ}, x: t⟩⟩. \overline{F} (\overline{new} t f)(f x)): \overline{νF} →\overline{F} (\overline{νF})
new_{νF}^{τ}  \overline{new} \overline{τ} ≡ (Λs. λf: s→\overline{F} (s). λx: s. ⟨s, ⟨f, x⟩⟩)\overline{τ}: (\overline{τ}→\overline{F} (\overline{τ}))→\overline{τ}→\overline{νF}

Table 3.2: Translation of inductive and projective terms

(λ⟨t, x: σ⟩. M) ≡ (λy: ∃t. σ. yυ(Λt. λx: σ. M)): (∃t. σ)→υ,

where in the latter definition the term M has type υ. It will be convenient to have this pattern matching syntax for terms of (translated) product type as well; thus, the F term (λ⟨x: σ, y: τ⟩. M) will be an abbreviation for

(λp: ∀t. (σ→τ→t)→t. pυ(λx: σ. λy: τ. M).

If we also write ⟨N, P ⟩ for (Λt. λf: σ→τ→t. f N P), then it is easy to see that both of these pattern matching terms behave as expected under reduction, i.e.,

(λ⟨t, x: σ⟩. M)⟨τ, N⟩ ⟶^{+} {N/x}{τ/t}M
(λ⟨x: σ, y: τ⟩. M)⟨N, P ⟩ ⟶^{+} {P/y}{N/x}M.

The general translation for an inductive type μt. σ was essentially given by Böhm and Berarducci [4], although they were mainly concerned with representing iteratively defined functions over the term algebra of an algebraic signature, touching only briefly on iteration at higher types. The corresponding translation for a projective type νt. σ was given independently by Hasegawa [24] and Wraith [58]. Here are the translations for the types:

\overline{μt. σ} ≡ ∀t. (\overline{σ}→t)→t
\overline{νt. σ} ≡ ∃t. \overline{(t→σ) × t}
≡ ∃t. ∀u. ((t→\overline{σ})→t→u)→u

The translations of the terms for these types are given in Table 3.2.

It is now a simple matter to verify that this translation preserves reduction in λ_{r}^{μν}.

Lemma 3.5.1 If M ⟶ N in λ_{r}^{μν}, then \overline{M} ⟶^{+} \overline{N}.

Proof. We will show two of the cases; the rest of the proof is entirely similar. We omit most types for brevity.

\overline{[M, N](ι_{1}P)} ≡ (λx. x\overline{υ} \overline{M} \overline{N})((λy. Λt. λf. λg. f y) \overline{P})
⟶^{+} (Λt. λf. λg. f \overline{P}) \overline{υ} \overline{M} \overline{N}
⟶^{+} \overline{M} \overline{P}
≡ \overline{MP}

unfold(new^{τ} M N) ≡ (λ⟨t, ⟨f, x⟩⟩. \overline{F} (\overline{new} t f)(f x))

((Λs. λg. λy. ⟨s, ⟨g, y⟩⟩) \overline{τ} \overline{M} \overline{N})
⟶^{+} (λ⟨t, ⟨f, x⟩⟩. \overline{F} (\overline{new} t f)(f x))⟨\overline{τ}, ⟨\overline{M}, \overline{N}⟩⟩
⟶^{+} \overline{F} (\overline{new} \overline{τ} \overline{M})(\overline{M} \overline{N})
≡ \overline{F (new^{τ} M)(MN)}

This lemma is precisely what we needed to complete the proof of strong normalization for λ_{r}^{μν}, since if there were an infinite reduction sequence from a term M in λ_{r}^{μν} then we would be able to construct an infinite reduction from \overline{M} in F. System F is strongly normalizing (see [17], for example), so we are done.

Retractive Types and Non-termination

The inductive and projective solutions are only defined if the functor F is covariant. In general, however, we want to be able to solve RDEs where the type variable may occur negatively; for example, to model the untyped λ-calculus we need to solve equations such as X ≅ X→X. The standard approach, due to Smyth and Plotkin [51], is to consider the category of embedding-projection pairs, also known as retracts. Given a category C such that each homset C(A, B) is enriched with a partial order structure ≤, we say that a pair (f: A→B, g: B→A) is a retract from A to B (and f is an embedding, g is a projection) if f; g = A (i.e., f followed by g is the identity arrow on A) and g; f ≤ B. The category of retracts, C^{R}, then has the same objects as C, with retracts for the arrows. The advantage of considering this category is that mixed variant functors on C may be replaced by covariant functors on C^{R}, which allows us to construct their least fixed point by taking a colimit of a suitable chain of retracts. For lack of a better name, we refer to types constructed in this manner as retractive; the notation we use is ρt. σ, or ρF.

In the category CPPO^{R}, the terminal object 1 from CPPO serves as the initial object, since (⊥, ◇) is a retract from 1 to any object A, where ⊥: 1→A is the least arrow in the homset CPPO(1, A), being the constant function which picks out the bottom element of A. We may thus construct a chain of retracts just as for the inductive case in the previous chapter, using (⊥, ◇): 1→F 1 in place of □: 0→F 0. However, we are interested in CPO^{R}, which has neither initial nor terminal objects. To find a chain of retracts in CPO^{R}, we observe that if F 1 is pointed, then there is a retract from 1 to F 1, given as before by (⊥, ◇), since F 1 has a bottom element; if F preserves retracts, then we may continue the chain as usual — indeed, it is the same chain as would have been formed in the subcategory CPPO^{R}. The key to being able to say which functors F will allow this construction is to introduce the lifting functor, which adds a bottom element to a cpo. Formally, we define ⊥: CPO→CPO to be UL, where L: CPO→CPPO_{⊥} is the left adjoint to the forgetful functor U from the category CPPO_{⊥} of cppo’s and strict (i.e., bottom-preserving) functions into CPO. The advantage of this categorical definition is that we can read off most of the desired equations for terms of lifted type from the equations in the model, just as we may read off the usual (β) and (η) rules from the categorical properties of cartesian closedness.

We will say that a functor F: CPO→CPO is (unconditionally) pointed if F X has a bottom element for any object X; it is conditionally pointed if F X has a bottom element whenever X does (a trivial example is the identity functor). The allowable functors then are the conditionally pointed ones (since 1 is pointed, F 1 will be) which preserve retracts. We may now use the lifting functor to form a syntactic class of functors which allow retractive fixed points.

When we have a type expression σ that is both covariant and conditionally pointed in a free type variable t, we may form the three recursive types μt. σ, νt. σ, and ρt. σ. An interesting fact in CPO is that the last two will always be isomorphic. If σ is unconditionally pointed, then all three coincide. This result is related to recent work of Barr, Freyd, and Fokkinga and Meijer [2, 14, 13], although it was arrived at independently.

4.1 Syntax of the language λ^{⊥ρ}

In this section we will describe the syntax for the types and terms of λ^{⊥ρ} as an extension to the language λ^{μν} of the previous chapter. We start by adding two type constructors: the lifted type σ_{⊥}, which corresponds to the operation which adds a bottom element to a cpo, and the retractive type ρt. σ, which corresponds to the recursive type found by the usual Smyth-Plotkin construction in CPO^{R}.

Not all type expressions σ may appear as the body of a retractive type, just as the bodies of inductive and projective types were restricted in the previous chapter to type expressions strictly positive in the type variable being bound. To state the restriction for retractive types (and also to relax the restriction for inductive and projective types) we need to formally introduce the concept of a pointed type. Intuitively, a pointed type is one which contains a bottom element, i.e., a least element with respect to the informationcontent ordering on the type. The bottom element represents a complete lack of information about the value, generally due to non-termination of an evaluation function. Following our cpo interpretation of the type constructors, we may see that the types 1 and σ_{⊥} are always pointed; it will also turn out that the retractive type ρt. σ is always pointed. If the types σ and τ are both pointed, then the product σ × τ will be pointed, since the pair consisting of the bottom elements of σ and τ will be the least element under the pointwise ordering of σ × τ. Similarly, if τ is pointed, then the function type σ→τ will be pointed for any σ, since the constant bottom function is less defined than any other element of σ→τ. The empty type 0 and the disjoint sum σ + τ will never be pointed; we do not even consider a type such as σ_{⊥} + 0 to be pointed, despite the fact that its cpo representation has a least element, since an element of a sum type necessarily conveys at least the information that it comes from, say, the first summand.

Since a recursive type μt. σ (or, mutatis mutandis, νt. σ or ρt. σ) is isomorphic to the unfolded type {μt. σ/t}σ, it is reasonable to consider a recursive type to be pointed whenever the body σ is. We have two choices when defining the pointedness of type expressions with free variables. If σ is pointed no matter what types are substituted for the free variables, then it is said to be unconditionally pointed. For example, the type expression s→t_{⊥} is unconditionally pointed, since t_{⊥} is always a pointed type expression. If the pointedness of σ depends on that of a free variable t, as for example in τ→t, then it is conditionally pointed with respect to t. Thus, our rule for inductive types will be that μt. σ is pointed if σ is unconditionally pointed. We may go further with projective and retractive types, saying that νt. σ and ρt. σ will be pointed if σ is conditionally pointed with respect to t. The reason for this difference comes from the respective constructions of the recursive types in CPO: an inductive type μF essentially results from an infinite number of applications of the functor F to the initial object 0, while the projective and retractive types start from 1. If F is only conditionally pointed, i.e., F (τ) is only pointed if τ is, then none of the finite approximations 0, F (0), F^{2}(0), …, to μF will be pointed; by continuity we thus expect that μF itself will not be pointed.^{1} By contrast, all of the approximations 1, F (1), F^{2}(1), …, to νF and ρF are pointed, so the limit types will be as well.

The introduction of retractive types necessitates a refinement of the definition of a type variable occurring covariantly in a type expression. Consider the expression ρs. s→t; at first glance it seems to be covariant in t, even strictly positive. However, one unfolding of this type expression produces (ρs. s→t)→t, in which t occurs both positively and negatively. The rule must be that ρs. σ is covariant in t only if σ is covariant in both s and t, or t does not occur at all in σ. This ensures that covariance is preserved under unfolding.

1This is another reason why we do not recognize types such as σ_{⊥} + 0 as pointed. If F (t) = σ_{⊥} + t, then F (0) would be pointed, although F^{2}(0), F^{3}(0), … would not. The intuition we prefer is that 0 is the canonical unpointed type, in the sense that if F (0) is pointed then F (τ) is pointed for all τ, i.e., F is unconditionally pointed. This is supported by the first lemma below.

We now state in words the full conditions on the bodies of recursive types; a system of inference rules is given below. These conditions will be justified in the final section of this chapter, which compares the three ways of defining recursive types. An inductive type μt. σ or a projective type νt. σ is well-formed if t occurs covariantly in σ and if each occurrence of t on the left of an arrow (hence on the left of an even number of arrows) is contained in some (unconditionally) pointed subterm of σ. For a retractive type ρt. σ to be wellformed, t may be of mixed variance in σ, but σ must be conditionally pointed with respect to t. Thus, for example, μt. (t→bool)→bool is not well-formed, since bool ≡ 1 + 1 is not pointed, but μt. (t_{⊥}→bool)→bool is. The intuitive reason for this is that the latter type is isomorphic to ((μs. ((s→bool)→bool)_{⊥})→bool)→bool; the body of this modified recursive type is pointed, so by the reasoning in section 4.5 the necessary inductive limit in CPO may instead be computed in CPO^{R}, where it is easy to show that the limit actually gives a fixed point. Note that, since the only pointed types in λ^{μν} are isomorphic to 1 (this may be proved by induction on the type formation rules, or by observing that the types of λ^{μν} may be modelled by sets and, up to isomorphism, 1 is the only pointed set), we did not lose any power in the previous chapter by restricting the bodies of inductive and projective types to be strictly positive in the bound variable. Also note that a retractive type will always be pointed, because the condition on the body for it to be well-formed is the same as the condition for it to be pointed.

These rules for type formation may be summarized by the inference system in Table 4.1. There are two kinds of judgement; the first, of the form Γ ▷ type σ, asserts that σ is a well-formed type expression given the context Γ; the second, of the form Γ ▷ ptd σ, asserts that σ is also pointed with respect to the context Γ. A context is a set of assumptions of the form ∗ t, where * may be either type or ptd; thus the judgement type s, ptd t▷ptd s→t asserts (correctly) that the well-formed type expression s→t is conditionally pointed with respect to t. If a judgement ∅ ▷ type σ is provable, then σ must be a well-formed type, i.e., a closed type expression; similarly, if ∅ ▷ ptd σ is provable then σ is a pointed type. The side condition (∗) on the μ and ν rules is that σ must be covariant with respect to t, and each occurrence of t on the left of an arrow must be contained in a subterm τ of σ such that Γ, type t ▷ ptd τ is provable.

We may now confirm our intuition that 0 is in a sense canonical among unpointed types:

Lemma 4.1.1 If ∅ ▷ ptd F (0) is provable, then so is type t ▷ ptd F (t); therefore, F is unconditionally pointed iff F (0) is pointed.

Proof. From a proof of ∅ ▷ ptd F (0) we may easily construct the desired proof of type t ▷ ptd F (t) by replacing each occurrence of the (: 0) axiom with the instance type t ▷ type t of the (: var) axiom, then renaming bound type variables away from t and adding type t to contexts as necessary.

Now that we have extended the types of λ^{μν}, we will describe the term formation rules corresponding to the additional types. For a retractive type ρF, we have terms which give the two directions of the isomorphism ρF ≃ F (ρF):

(ρ Intro) ∅ ▷ fold_{ρF}: F (ρF)→ρF

(ρ Elim) ∅ ▷ unfold_{ρF}: ρF →F (ρF).

We could also introduce terms analogous to it_{μF} and new_{νF}, representing the fact that a retractive type is both an initial F -algebra and a terminal F -coalgebra; however, the additional apparatus needed to define these terms is prohibitive — e.g., since ρF is an initial F -algebra only in CPPO^{R}, the subcategory of pointed cpo’s and retractions, we would first have to prove that M: F (τ)→τ was a retraction before constructing the term it_{ρF}^{τ} M: ρF →τ. We avoid this complexity at the expense of obtaining a less powerful proof system which does not directly reflect the categorical interpretation. The fact that a retractive type is a fixed point of F is sufficient to define a term fix^{σ}: (σ→σ)→σ which acts as a fixed point operator on terms, i.e., fix^{σ}M → → M(fix^{σ}M) for any term M: σ→σ. Using fix^{σ} we may define it_{ρF}^{τ} M and new_{ρF}^{τ} M as desired; the cost of being able to do this is that we must add a proof rule for fixed point induction to (partially) substitute for the missing extensional rules involving it_{ρF} and new_{ρF}.

(: var)  ∗ t ▷ type t  ptd t ▷ ptd t  (.var)

(: add var)

\frac{Γ ▷ type σ}{Γ, ∗ t ▷ type σ}

\frac{Γ ▷ ptd σ}{Γ, ∗ t ▷ ptd σ}
(.add var)
(: 0)  ∅ ▷ type 0
(: 1)  ∅ ▷ type 1  ∅ ▷ ptd 1  (.1)

(: +)

                       \frac{Γ ▷ type σ, Γ ▷ type τ}{Γ ▷ type σ + τ}

(: ×)

                       \frac{Γ ▷ type σ, Γ ▷ type τ}{Γ ▷ type σ × τ}

\frac{Γ ▷ ptd σ, Γ ▷ ptd τ}{Γ ▷ ptd σ × τ}
(.×)

(: →)

                       \frac{Γ ▷ type σ, Γ ▷ type τ}{Γ ▷ type σ→τ}

\frac{Γ ▷ type σ, Γ ▷ ptd τ}{Γ ▷ ptd σ→τ}
(.→)

(: ⊥)

                             \frac{Γ ▷ type σ}{Γ ▷ type σ_{⊥}}

                                                    \frac{Γ ▷ type σ}{Γ ▷ ptd σ_{⊥}}

(.⊥)
(: μ)  \frac{Γ, type t ▷ type σ}{Γ ▷ type μt. σ} (∗)  \frac{Γ, type t ▷ ptd σ}{Γ ▷ ptd μt. σ} (∗)  (.μ)
(: ν)  \frac{Γ, ∗ t ▷ type σ}{Γ ▷ type νt. σ} (∗)  \frac{Γ, ptd t ▷ ptd σ}{Γ ▷ ptd νt. σ} (∗)  (.ν)

(: ρ)

\frac{Γ, ptd t ▷ ptd σ}{Γ ▷ type ρt. σ}

\frac{Γ, ptd t ▷ ptd σ}{Γ ▷ ptd ρt. σ}
(.ρ)

Table 4.1: Type formation and pointedness rules

Here is the definition of the least fixed point operator using retractive types. The definition we use is based on Turing’s combinator Θ (see [1], for example):

(λxf. f(xxf))(λxf. f(xxf)).

This untyped term may be typed if x has the retractive type υ ≡ ρt. (t→(σ→σ)→σ), where f will have type σ→σ for some pointed type σ, and t does not occur free in σ. The self-application of x thus becomes well-formed when it is written unfold_{υ} xx. Therefore, we make the following definition for fix^{σ}: (σ→σ)→σ:

(λx: υ. λf: σ→σ. f(unfold_{υ} xxf))(fold_{υ}(λx: υ. λf: σ→σ. f(unfold_{υ} xxf))).

To motivate the terms for the lifted type σ_{⊥}, we first consider the subcategory CPPO_{⊥} of pointed cpo’s and strict functions. If X is a pointed cpo, then it must have a bottom element, ⊥^{X}. The strict functions from X to Y are those which preserve bottom, i.e., f: X→Y is strict if f(⊥^{X}) = ⊥^{Y}. If we let L: CPO→CPPO_{⊥} be the functor such that L(X) is the pointed cpo X with a bottom element added and L(f: X→Y) is the function f extended by f(⊥^{L(X)}) = ⊥^{L(Y)}, then there is an isomorphism φ from the homset CPPO_{⊥}(L(X), Y) to CPO(X, U(Y)), where U: CPPO_{⊥}→CPO is the obvious forgetful functor. That is, given any strict function f: L(X)→Y, there is a unique function φ(f): X→U(Y), obtained by dropping the bottom element from the domain; also, given any function g: X→U(Y) there is a unique strict function φ^{−1}(g): L(X)→Y, obtained by adding a bottom element to the domain and requiring that φ^{−1}(g) map it to the bottom of Y (which must be pointed because it is an object of CPPO_{⊥}). This isomorphism is natural in X and Y, hence we have an adjunction L ⊣ U.

Lifting arises from this adjunction by taking the interpretation of σ_{⊥} to be the application of the endofunctor UL to the object corresponding to σ. One way of describing the adjunction L ⊣ U is by giving a natural transformation η: CPO \underrightarrow{.} UL, the unit of the adjunction, such that each arrow η_{X}: X→UL(X) is universal from X to U, i.e., for any other arrow f: X→U(Y) there is a unique arrow g: L(X)→Y such that f = U(g) ∘ η_{X} (see [32], for example). This arrow g is the strict function φ^{−1}(f) described above.

In general, an adjunction L ⊣ U for functors L: C→D and U: D→C creates a monad in C. The monad endofunctor T is given by UL, the unit η: C \underrightarrow{.} T is just the unit of the adjunction, and the multiplication μ: T T \underrightarrow{.} T is UεL, where ε: LU \underrightarrow{.} D is the counit of the adjunction; details may be found in [31, 32], for example. For our purposes, it will be more useful to consider an alternate description of a monad, the Kleisli triple, which is discussed in [37]. Instead of the multiplication μ, a Kleisli triple provides an arrow f^{∗}: T X→T Y for every arrow f: X→T Y of C. The multiplication μ_{X} may then be obtained from (id^{T X})^{∗}; conversely, the arrow f^{∗} may be defined in terms of μ as μ_{Y} ∘ T f. In terms of the adjunction description above, the arrow f^{∗} is simply the arrow U(φ^{−1}(f)) found by the universality of η_{X}.

A monad (T, η,^{∗}) may be represented in our language by the following pair of term formation rules:

(T Intro)  \frac{Γ ▷ M: σ}{Γ ▷ ⌊M⌋: T σ}

(T Elim)  \frac{Γ, x: σ ▷ M: T τ}{Γ ▷ (λ⌊x: σ⌋. M): T σ→T τ}

The introduction rule represents composition with η, and the elimination rule is the operation of constructing f^{∗} from f.^{2} There is as usual some freedom about whether to express functions externally via a free variable or internally via a binding operator; we have chosen the form here because it fits in well with our patternmatching syntax (although in this case the term (λ⌊x: σ⌋. M) is part of the basic syntax instead of syntactic sugar). Indeed, we will add ⌊P⌋ to our list of patterns, so that, for example, let ⌊x: σ⌋ = M in N is an abbreviation for (λ⌊x: σ⌋. N)M. This let syntax is essentially the same as that used by Moggi for his computational lambda calculus [37].

In the special case that the category D is a subcategory of C and the functor U: D→C is the inclusion, then we may regard the objects and arrows of D as being objects and arrows of C with some special property (namely, that they belong to the subcategory). If we have judgements of the form ▷“σ is in D” and Γ ▷ “M: σ→τ is in D”, then we may use this extra information to obtain a more expressive representation of the adjunction L ⊣ U. We will have the same formation rule for the unit η:

(L Intro)  \frac{Γ ▷ M: σ}{Γ ▷ ⌊M⌋: Lσ.}

For the elimination rule, however, we may start with any arrow f: X→UY, for Y an object of D, and construct the arrow φ^{−1}(f): LX→Y, which is actually an arrow in D:

(L Elim)  \frac{Γ, x: σ ▷ M: τ, ▷“τ is in D”}{Γ ▷ (λ⌊x: σ⌋. M): Lσ→τ.}

We should thus include in the rules for these special judgements the facts that “Lσ is in D” for all types σ, and “(λ⌊x: σ⌋. M): Lσ→τ is in D”.

We are finally ready to introduce the term formation rules for lifting. The subcategory D is CPPO_{⊥}, so the judgement saying that a type σ is in D becomes the side-condition that σ is pointed. The judgement that a term M: σ→τ is in D becomes the statement that M is strict. To be able to reason about strict functions in the proof system, we will need a term constant at each pointed type giving the bottom element of that type:

2Actually, because the rest of the variables in the context Γ are not affected by the elimination rule, this correspondence only holds if we have a strong monad. A monad is strong if there is a natural transformation t, the tensorial strength, such that the components t_{X,Y} : X × T Y →T (X × Y) satisfy certain equations. Thus, if the interpretation of Γ, x: σ ▷ M: T τ is the arrow f: γ × σ→T τ, then the correct interpretation of Γ ▷ (λ⌊x: σ⌋. M): T σ→T τ is the arrow Λ(f^{∗} ∘ t_{γ,σ}): γ→(T σ→T τ), where Λ is the abstraction map. See [37] for more details.

(bottom)  \frac{∅ ▷ ptd σ}{∅ ▷ ⊥^{σ}: σ.}

The natural transformation η is then represented in λ^{⊥ρ} by the term formation rule

(⊥ Intro)  \frac{Γ ▷ M: σ}{Γ ▷ ⌊M⌋: σ_{⊥}.}

The term demonstrating the universality of η is given by the rule

(⊥ Elim)  \frac{Γ, x: σ ▷ M: τ, ∅ ▷ ptd τ}{Γ ▷ (λ⌊x: σ⌋. M): σ_{⊥}→τ;}

when we present the equational proof system in the next section, the statement that this abstraction is strict will be given by the axiom

Γ ▷ (λ⌊x: σ⌋. M)⊥^{σ_{⊥}} = ⊥^{τ} : τ.

In comparing our calculus to Moggi’s Computational Lambda Calculus, we note that our treatment of lifting differs from Moggi’s in two important respects. First, because we are dealing with the specific operation of lifting instead of an arbitrary monad of computations, we will get more terms and more provable equations. Specifically, by introducing strict functions and defining lifting as an adjunction, we will find some equations that hold for all pointed types, whereas if we only defined lifting as a monad they would only hold for lifted types. The second difference is that in Moggi’s system, all functions return values of the computation type; we require lifting to be indicated more explicitly, so that functions are expressible which do not represent computations of the lifted type (indeed, the entire sublanguage λ^{μν} is concerned with defining functions which do not return lifted types, because they always terminate).

Now we may extend the definition of F (M) to cover lifted and retractive types:

• if F (t) = G(t)_{⊥}, then F (M) = (λ⌊x: G(σ)⌋. ⌊G(M)x⌋);

• if F (t) = ρs. G(s, t), then F (M) = fix^{F (σ)→F (τ)}(λf: F (σ)→F (τ). fold_{ρs. G(s,τ)} ∘G(f, M) ∘ unfold_{ρs. G(s,σ)}).

Note that, because t must occur covariantly in F (t), the type expression G(s, t) in the retractive case must be covariant in both s and t. The term G(f, M) was discussed in the proof that “functor” application preserves composition; it is equal to both G(f, τ) ∘ G(F (σ), M) and G(F (τ), M) ∘ G(f, σ), by the usual definition of the application of a bifunctor.

4.2 Equational proof system for λ^{⊥ρ}

We will extend the proof system given in the previous chapter for λ^{μν} to provide a formal semantics for the types and terms just introduced. In addition to proving equations between terms, we will also need the auxiliary concept of an approximation ordering among terms. The categorical interpretation of this ordering is that we have a partial order structure on the homsets, reflecting the notion of increasing information content among the functions. A category whose homsets are enriched in this way is known as an O-category ([57]; see also [51]). For example, among functions in a given homset whose codomain is pointed, the constant bottom function will be less defined than all other functions; it is the least element of the homset. We will write Γ ▷ M ≤ N : σ for the statement that the term Γ ▷ M: σ is less than or equal to Γ ▷ N: σ, i.e., that the arrow from γ to σ corresponding to M is less defined than that corresponding to N.

Just as for equality, we need some structural rules for approximation. Note that we need an extra “congruence” rule for strict abstraction, since it is a new binding operator. We do not need to go back and introduce a corresponding equality rule, since we may derive it from (≤ str abs) by using (≤ eq) and (sym) to split the hypothesis into two approximations, applying the abstraction rule, then recombining the approximations into the desired equality with (≤ antisym).

(≤ eq)  \frac{Γ ▷ M = N : σ}{Γ ▷ M ≤ N : σ}

(≤ antisym)  \frac{Γ ▷ M ≤ N : σ, Γ ▷ N ≤ M : σ}{Γ ▷ M = N : σ}

(≤ trans)  \frac{Γ ▷ M ≤ N : σ, Γ ▷ N ≤ P : σ}{Γ ▷ M ≤ P : σ}

(≤ abs)  \frac{Γ, x: σ ▷ M ≤ N : τ}{Γ ▷ (λx: σ. M) ≤ (λx: σ. N) : σ→τ}

(≤ str abs)  \frac{Γ, x: σ ▷ M ≤ N : τ}{Γ ▷ (λ⌊x: σ⌋. M) ≤ (λ⌊x: σ⌋. N) : σ_{⊥}→τ} if τ is pointed

(≤ app)  \frac{Γ ▷ M ≤ N : σ→τ, Γ ▷ P ≤ Q : σ}{Γ ▷ MP ≤ NQ : τ}

(≤ add var)  \frac{Γ ▷ M ≤ N : σ}{Γ, x: τ ▷ M ≤ N : σ}

We may use these rules and the previous equational axioms and rules to establish the following analogue to the substitution lemma:

Lemma 4.2.1 If the approximations Γ, x: σ ▷ M ≤ N : τ and Γ ▷ P ≤ Q : σ are provable, then so is Γ ▷ {P/x}M ≤ {Q/x}N : τ.

Proof. The proof is identical to the equational version in the previous chapter, with the addition of two applications of the (≤ eq) rule to establish that Γ ▷ {P/x}M ≤ (λx: σ. M)P : τ and Γ ▷ (λx: σ. N)Q ≤ {Q/x}N : τ are both true.

The two remaining rules for approximation establish some of the properties of recursively defined functions. Of course, we cannot expect to obtain a proof system which is complete for reasoning about equality between terms (or even programs) of λ^{⊥ρ}, since all partial recursive functions are representable in the language. Equality of partial recursive functions is not recursively enumerable, so we can not have a complete proof system.

The first of the remaining approximation rules asserts that ⊥^{σ} is the least element of pointed type σ:

(⊥ ≤)  \frac{∅ ▷ ptd σ}{Γ ▷ ⊥^{σ} ≤ M : σ.}

The other rule is a form of Scott’s fixed point induction ([50]; see also [33]). We only consider the special case where the inclusive predicate is an approximation. This is the most complex inference rule of the proof system; the second hypothesis should be read as saying that if the approximation Γ ▷ P c ≤ Qc : τ is provable for some fresh term constant c of type σ, then so is Γ ▷ P (Mc) ≤ Q(Mc) : τ. Since c must be a previously uninterpreted constant, this is proof-theoretically equivalent to the (non-finitary) hypothesis that Γ ▷ P N ≤ QN : τ implies Γ ▷ P (MN) ≤ Q(MN) : τ, for every term Γ ▷ N: σ.

(fpind)  \frac{Γ ▷ P ⊥^{σ} ≤ Q⊥^{σ} : τ, ( \frac{Γ ▷ P c ≤ Qc : τ}{Γ ▷ P (Mc) ≤ Q(Mc) : τ} )}{Γ ▷ P (fix^{σ}M) ≤ Q(fix^{σ}M) : τ} c fresh

This rule is somewhat unsatisfactory for two reasons. First is its complexity; however, it is a common rule used for proving facts about fixed points, and the examples below will make frequent use of it in ways that no simpler rule we tried could handle. Second, it is the only major rule without a direct categorical motivation; indeed, since it asserts a fact about fix^{σ}, which is only a defined term in λ^{⊥ρ}, it seems quite ad hoc. It would be more satisfying to derive this rule from a rule expressing the fact that a retractive type is an initial algebra, but as we have already noted, there are technical problems with this approach which we have not yet solved. The price we will pay for using (fpind) is that we have not been able to prove some equations about retractive types that would have followed easily from initiality; for example, we do not know how to use fixed point induction to show that F (id) = id, when F contains a retractive type (see below). The recent work of Crole and Pitts on their FIX-Logic [12] may offer a solution to this difficulty, although we have not yet been able to work out the precise relation between their system and ours.

To finish the proof system for λ^{⊥ρ}, we need to present the (β) and (η) rules for the new types. For a retractive type ρF, we simply take these to be the two equations establishing that fold_{ρF} and unfold_{ρF} are inverses:

(ρβ) ∅ ▷ unfold_{ρF} ∘ fold_{ρF} = id^{F (ρF)} : F (ρF)→F (ρF)

(ρη) ∅ ▷ fold_{ρF} ∘ unfold_{ρF} = id^{ρF} : ρF →ρF.

In terms of our general discussion of monads in the previous section, the rules for an arbitrary monad (T, η,^{∗}) would be

(T β) Γ ▷ (λ⌊x: σ⌋. M)⌊N⌋ = {N/x}M : T τ

(T η) Γ ▷ (λ⌊x: σ⌋. ⌊x⌋) = id^{T σ} : T σ→T σ

(T η′) Γ ▷ (λ⌊y: τ⌋. N) ∘ (λ⌊x: σ⌋. M) = (λ⌊x: σ⌋. (λ⌊y: τ⌋. N)M) : T σ→T υ;

these are a direct translation of the equations f^{∗} ∘ η_{X} = f, η_{X}^{∗} = id^{T X}, and g^{∗} ∘ f^{∗} = (g^{∗} ∘ f)^{∗} for a Kleisli triple, as found in [37].

In the special case that we have an adjunction L ⊣ U where U: D→C is an inclusion functor, we may improve on the monad equations by using information about the objects and arrows of D:

(Lβ) Γ ▷ (λ⌊x: σ⌋. M)⌊N⌋ = {N/x}M : τ

(Lβ′) Γ ▷ “(λ⌊x: σ⌋. M): Lσ→τ is in D”

(Lη)  \frac{Γ ▷ “M: Lσ→τ is in D”}{Γ ▷ (λ⌊x: σ⌋. M⌊x⌋) = M : Lσ→τ} for x ∉ FV(M).

The (Lβ) axiom asserts the commutativity of the diagram

[figure: X; UL(X); η_{X}; f; U(Y); U(φ^{−1}(f))],

whereas the (Lη) rule establishes that φ^{−1}(f) is the unique arrow which makes the diagram commute; this is just the statement discussed above that η_{X} is universal from X to U. The hypothesis on the (Lη) rule is necessary because the arrow represented by M needs to be an arrow in D. Similarly, we also need the (Lβ′) rule to establish that the term representing φ^{−1}(f) is in D. With the additional knowledge that the subcategory D must be closed under formation of identities and composition, i.e., id^{σ} is in D if σ is in D and M ∘ N is in D if M and N are in D, it is easy to show that these rules for L imply those given for T above. For example, since id^{T σ} is in D, we find using (Lη) that (λ⌊x: σ⌋. ⌊x⌋) = (λ⌊x: σ⌋. id^{T σ}⌊x⌋) = id^{T σ}, which is (T η).

The particular instance of these rules for lifting leads to the following:

(⊥β) Γ ▷ (λ⌊x: σ⌋. M)⌊N⌋ = {N/x}M : τ

(⊥β′) Γ ▷ (λ⌊x: σ⌋. M)⊥^{σ_{⊥}} = ⊥^{τ} : τ

(⊥η)  \frac{Γ ▷ M⊥^{σ_{⊥}} = ⊥^{τ} : τ}{Γ ▷ (λ⌊x: σ⌋. M⌊x⌋) = M : σ_{⊥}→τ} for x ∉ FV(M).

However, after some experience using these rules we discover that they are not quite strong enough to represent our intuition about lifting. In particular, they do not seem to reflect the desired property that the only elements of the lifted type σ_{⊥} are the elements of σ plus bottom. Therefore, we will use the following more powerful inference rule in place of (⊥η):

(⊥ext)  \frac{Γ ▷ M⊥^{σ_{⊥}} = N⊥^{σ_{⊥}} : τ, Γ, x: σ ▷ M⌊x⌋ = N⌊x⌋ : τ}{Γ ▷ M = N : σ_{⊥}→τ.}

It is easy to see that taking N ≡ (λ⌊x: σ⌋. M⌊x⌋) in this rule lets us derive (⊥η).

Two equations which intuitively hold for the lifting monad and yet which do not seem provable without using (⊥ext) were suggested to us by Eugenio Moggi:

(λ⌊x: σ⌋. (λ⌊y: σ⌋. M)N)N = (λ⌊x: σ⌋. {x/y}M)N, x not in N
(λ⌊x: σ⌋. (λ⌊y: τ⌋. M)N)P = (λ⌊y: τ⌋. (λ⌊x: σ⌋. M)P)N, x not in N ; y not in P

These equations are not true in arbitrary monads. The first one says that, for the purposes of strict evaluation, repeating the evaluation step makes no difference (since if the argument is going to diverge then it will do so the first time); the second says that order of strict evaluation does not matter, as long as both N and P must be evaluated eventually. These are very easy to prove using the “reasoning by cases” made available by the (⊥ext) rule; for example, the terms (λz: σ_{⊥}. (λ⌊x: σ⌋. (λ⌊y: σ⌋. M)z)z) and (λz: σ_{⊥}. (λ⌊x: σ⌋. {x/y}M)z) both are equal to ⊥^{τ} when applied to ⊥^{σ_{⊥}}, and similarly both are equal to {w/x}{w/y}M when applied to ⌊w⌋, hence they are equal by (⊥ext); apply each to N to get the first equation. We would of course prefer it if the categorically motivated rules were enough to make such reasoning possible, but we have not managed to do this.

We may now prove several useful lemmas about the terms of λ^{⊥ρ}. As mentioned above, we are not able to prove that construction of the term F (M) preserves identities or composition when F (t) contains a retractive type which depends on t. The reason is that fixed point induction does not seem strong enough to prove that, for example, the identity function id^{σ} is the least fixed point of the functional (λf: σ→σ. fold_{ρG} ∘G(f)∘ unfold_{ρG}), where G is a covariant functor which is assumed to preserve identities by the inductive hypothesis. However, for practical purposes this is not a problem. Since the only way F (t) can contain a retractive type ρs. G(s, t) which depends on t is if G is covariant in both s and t, we will find in Section 4.5 that, at least with respect to creating isomorphic types in the cpo model, the retractive type may be replaced by the projective type νs. G(s, t), for which we have the appropriate induction rule.

First of all, we will need to know how functor application interacts with approximation:

Lemma 4.2.2 Functor application is locally monotonic, i.e., if the approximation Γ ▷ M ≤ N : σ→τ is provable, then so is Γ ▷ F (M) ≤ F (N) : F (σ)→F (τ).

Proof. We merely need to apply the substitution lemma for approximation to the equation Γ, f: σ→τ ▷ F (f) = F (f) : F (σ)→F (τ). Now we may prove a partial extension of the fact that substituting a term in a type behaves like functor application:

Lemma 4.2.3 If F (t) does not contain any subterms of the form ρs. υ, where t occurs free in υ, then application of F to a term preserves composition and identities, i.e., F (M ∘ N) = F (M) ∘ F (N) and F (id) = id.

Proof. Most of this lemma was proved in Section 3.2 as Lemma 3.2.3; we only need to consider the case where F (t) is a lifted type expression. If F (t) = G(t)_{⊥}, then

F (M) ∘ F (N) = F (M) ∘ (λ⌊x: G(σ)⌋. ⌊G(N)x⌋)
= (λ⌊x: G(σ)⌋. F (M)((λ⌊x: G(σ)⌋. ⌊G(N)x⌋)⌊x⌋))
= (λ⌊x: G(σ)⌋. (λ⌊y: G(τ)⌋. ⌊G(M)y⌋)⌊G(N)x⌋)
= (λx: G(σ). ⌊G(M)(G(N)x)⌋)
= F (M ∘ N);

similarly, F (id^{σ}) = (λ⌊x: G(σ)⌋. ⌊x⌋) = id^{F (σ)}. The impact on previous results of the restriction on the form of F in this lemma is that the proof of Lemma 3.2.4, which states that the defined terms for unfold_{μF} and fold_{νF} are inverses for the primitives fold_{μF} and unfold_{νF}, is only valid for functors of the restricted form. This provides another argument for including the inverses as primitives.

As an example of the kind of proof that is almost trivial given fixed point induction, we observe that we could have done away with the bottom constants ⊥^{σ} for each pointed type σ by defining them to be the least fixed points of the identity:

Lemma 4.2.4 If σ is pointed, then fix^{σ} id^{σ} = ⊥^{σ}.

Proof. Since id^{σ} ⊥^{σ} ≤ ⊥^{σ} and, whenever id^{σ} c ≤ ⊥^{σ}, then also id^{σ}(id^{σ} c) ≤ ⊥^{σ}, it follows by (fpind) that fix^{σ} id^{σ} = id^{σ}(fix^{σ} id^{σ}) ≤ ⊥^{σ}. Using (⊥ ≤) we may change this approximation into an equality. We may easily obtain more information about the structure of the bottom elements for pointed types which do not contain any retractive types:

Lemma 4.2.5 If all the necessary type expressions are pointed, then we may prove

• ⊥^{1} = ◇;

• ⊥^{σ×τ} = ⟨⊥^{σ}, ⊥^{τ} ⟩;

• ⊥^{σ→τ} = (λx: σ. ⊥^{τ});

• ⊥^{μF} = fold_{μF} ⊥^{F (μF)};

• ⊥^{νF} = new_{νF}^{1} ⊥^{1→F (1)}⊥^{1}.

Proof. All the cases follow the general pattern of using the substitution lemma for approximation to build up a term which is equivalent by one of the extensional rules to the desired bottom.

• ⊥^{1} = ◇ is just an instance of the (1η) axiom.

• ⊥^{σ} ≤ π_{1}⊥^{σ×τ} and ⊥^{τ} ≤ π_{2}⊥^{σ×τ}, so by (≤ ⊥), substitution, and (×η) we find ⊥^{σ×τ} ≤ ⟨⊥^{σ}, ⊥^{τ} ⟩ ≤ ⟨π_{1}⊥^{σ×τ} , π_{2}⊥^{σ×τ} ⟩ = ⊥^{σ×τ}.

• ⊥^{τ} ≤ ⊥^{σ→τ} x, hence ⊥^{σ→τ} ≤ (λx: σ. ⊥^{τ}) ≤ (λx: σ. ⊥^{σ→τ} x) = ⊥^{σ→τ}.

• ⊥^{F (μF)} ≤ unfold_{μF} ⊥^{μF}, so similarly we find (using either (μη′) or, since F satisfies the restrictions mentioned above, Lemma 3.2.4) ⊥^{μF} ≤ fold_{μF} ⊥^{F (μF)} ≤ fold_{μF} (unfold_{μF} ⊥^{μF}) = ⊥^{μF}. Note that if we were to use this as a definition for ⊥^{μF} it would be well-founded, because we may show that, since F is unconditionally pointed, the definition of ⊥^{F (μF)} will not need the term ⊥^{μF}. The same reasoning would not hold if we tried to define ⊥^{νF} as fold_{νF} ⊥^{F (νF)}, or similarly for ⊥^{ρF}, because F need only be conditionally pointed; for example, νt. t is a pointed type which would lead to the non-well-founded definition ⊥^{νt. t} = fold_{νt. t} ⊥^{νt. t}.

• We first note that F (⊥^{1→νF}) is strict, because

⊥^{F (νF)} ≤ F (⊥^{1→νF}) ∘ ⊥^{F (1)}
≤ (F (⊥^{1→νF}) ∘ F (⊥^{νF →1}))⊥^{F (νF)}
≤ F (id^{νF})⊥^{F (νF)}
= ⊥^{F (νF)}.

We may also show that unfold_{νF} is strict, in the same way we proved that fold_{μF} is strict in the previous item. Therefore, the equation unfold_{νF} ∘⊥^{1→νF} = F (⊥^{1→νF}) ∘ ⊥^{1→F (1)} is true because both sides are equal to the bottom function ⊥^{1→F (νF)}. This is the form we need to apply (νη), resulting in ⊥^{1→νF} = new_{νF}^{1} ⊥^{1→F (1)}; applying both sides to ⊥^{1} and using the above characterization of a bottom of functional type yields the desired result.

In the interpretation of λ^{⊥ρ} in the category CPO, we observe that application of the lifting functor to the initial object, i.e., the empty cpo, yields a terminal object, i.e., a cpo with exactly one element. It is an interesting consequence of our rules for lifting that this is true in all models of λ^{⊥ρ}:

Lemma 4.2.6 The types 0_{⊥} and 1 are isomorphic.

Proof. We will show that the terms ⊥^{0_{⊥}→1} and ⊥^{1→0_{⊥}} are inverses. Since both terms are strict, either way of composing them will result in a bottom function, hence we only need to show that ⊥^{1→1} = id^{1} and ⊥^{0_{⊥}→0_{⊥}} = id^{0_{⊥}}. The first equation is trivial, since by the (1η) rule, all terms of type 1→1 are equal to (λ◇. ◇). For the second equation, since both sides are strict functions, if we can prove x: 0 ▷ ⊥^{0_{⊥}→0_{⊥}}⌊x⌋ = id^{0_{⊥}}⌊x⌋ : 0_{⊥}, then by using the (derived) strict abstraction congruence rule and (⊥η) we are done. But this last equation is true, since for any term x: 0 ▷ M: σ we find by (→β) and (0η) that M = (λx: 0. M)x = □^{σ}x is true, i.e., all such terms are equal.

This isomorphism is an instance of a general condition for showing that lifting is a monad with zero, a concept introduced by Wadler [54]. The monad natural transformations η: C \underrightarrow{.} T and μ: T T \underrightarrow{.} T receive their names “unit” and “multiplication” in part because of an analogy with the corresponding concepts in a monoid; the diagrams which must commute for a monad may then be seen as statements that multiplication is associative and has the unit as an identity:

[figure: T T X; T X; μ_{X}; T T T X; T T X; T μ_{X}; μ_{T X}; μ_{X}] [figure: T X; id; T X; T T X; η_{T X}; T X; T η_{X}; μ_{X}; id].

Wadler observed that many common monads also have zeroes with respect to multiplication. In a category with a terminal object, we may present a zero for a monad by giving a natural transformation ζ: 1 \underrightarrow{.} T such that the following diagram commutes:

[figure: T X; ζ_{X}; 1; T T X; ζ_{T X}; T 1; T ζ_{X}; μ_{X}; ζ_{X} ∘ ◇_{T 1}],

where ◇_{T 1} is the unique arrow from T 1 to 1. For the lifting monad, it is easy to see that the bottom arrow from 1 to X_{⊥} will act as a zero, since the multiplication μ_{X} collapses both the bottom element ⊥^{(X_{⊥})_{⊥}} and the lifted bottom element ⌊⊥^{X_{⊥}}⌋ down to the bottom of X_{⊥}.

This author and Michael Johnson [55] independently noticed the following special case of this definition: if a category with a monad (T, η, μ) and a terminal object 1 also has an initial object 0 and if there is an isomorphism ⊥: 1→T 0, then the natural transformation whose X component is the arrow T □_{X} ∘ ⊥: 1→T X will act as a zero for the monad. This follows by a simple diagram chase, using the uniqueness of the arrows ◇_{X}: X→1 and □_{X}: 0→X, plus the fact that ◇_{T 0} is an inverse for the given arrow ⊥. The preceding lemma thus allows us to confirm the above observation about the zero of the lifting monad, since the term corresponding to T □_{X} ∘ ⊥ is (λ⌊x: X⌋. ⌊□^{X}x⌋) ∘ ⊥^{1→0_{⊥}}, which is equal to ⊥^{1→X_{⊥}} by the (⊥β′) rule.

4.3 The reduction system λ_{r}^{⊥ρ}

We may now consider an operational semantics for λ^{⊥ρ}, given as the obvious extension to that presented for λ^{μν}. The full reduction system λ_{r}^{⊥ρ} will still be confluent, although it will of course no longer be normalizing. A notion of evaluating a term must therefore be relative to some strategy for choosing a reduction path. We will show that a lazy strategy is computationally adequate with respect to finding normal forms of programs.

As usual, we obtain the reduction rules from the equational proof system by directing the (β) axioms in the direction of decreasing complexity of terms. Here is the list of rules:

(+β_{1})_{r} [M, N](ι_{1}P) ⟶ MP

(+β_{2})_{r} [M, N](ι_{2}P) ⟶ NP

(×β_{1})_{r} π_{1}⟨M, N⟩ ⟶ M

(×β_{2})_{r} π_{2}⟨M, N⟩ ⟶ N

(→β)_{r} (λx: σ. M)N ⟶ {N/x}M

(μβ)_{r} it_{μF} M(fold_{μF} P) ⟶ M(F (it_{μF} M)P)

(νβ)_{r} unfold_{νF} (new_{νF} MP) ⟶ F (new_{νF} M)(MP)

(μβ′)_{r} unfold_{μF} (fold_{μF} M) ⟶ M

(νβ′)_{r} unfold_{νF} (fold_{νF} M) ⟶ M

(ρβ)_{r} unfold_{ρF} (fold_{ρF} M) ⟶ M

(⊥β)_{r} (λ⌊x: σ⌋. M)⌊N⌋ ⟶ {N/x}M

(⊥β′)_{r} (λ⌊x: σ⌋. M)⊥^{σ_{⊥}} ⟶ ⊥^{τ} .

As with λ_{r}^{μν}, we may leave the types and typing contexts implicit because we have a subject reduction lemma; intuitively, types are only need at compile time.

Lemma 4.3.1 (Subject Reduction) If Γ ▷ M: σ is well-formed and M ⟶ N, then Γ ▷ N: σ is also well-formed.

For the proof of confluence we will simply observe that λ_{r}^{⊥ρ} is a regular combinatory reduction system (after erasing the types, which the previous lemma has shown are unnecessary for reduction). A combinatory reduction system (CRS), as introduced by Klop [28], is a generalization of term rewriting systems to include variable binding operators and substitution. Our system λ_{r}^{⊥ρ} is a CRS with two binding forms, each of which binds one variable: (λx. ·) and (λ⌊x⌋. ·). In fact it is a regular CRS, because it is left-linear (no meta-variable appears more than once on the left-hand side of a rule) and non-ambiguous (there are no critical pairs).

Theorem 4.3.2 (Confluence) If M ⟶ N and M ⟶ P, then there is a term Q such that N ⟶ Q and P ⟶ Q.

Proof. Immediate from [28], Theorem II.3.11.

Klop also shows that if a regular CRS has the additional property that it is left-normal, then it satisfies a standardization theorem. Recall from Chapter 2 that the definition Klop gives for left-normal is that all of the constants (including binding operators) are to the left of the meta-variables in all of the reduction rules. The effect of this restriction is that if terms are evaluated from left to right, then all the necessary redexes will be created in an orderly fashion.

Our system λ_{r}^{⊥ρ} as it stands is not left-normal; for example, in the (+β_{1})_{r} rule, the constant ι_{1} appears to the right of the meta-variables M and N. To see concretely how this would affect a left-to-right reduction strategy, consider the term [id, fix id](id(ι_{1}◇)). If we employed a strategy of strict left-to-right evaluation, then the reduction would get hung in a loop trying to evaluate the right arm of the choice, never reaching the (→β)_{r} redex at the right, which must be evaluated to complete the (+β_{1})_{r} redex and reach the normal form ◇.

The non-left-normal rules are (+β_{1})_{r}, (+β_{2})_{r}, (μβ)_{r}, (⊥β)_{r}, and (⊥β′)_{r}. There are two easy ways to fix these and obtain a left-normal reduction system. Either we may rearrange the syntax of terms, so that these rules become left-normal by Klop’s definition, or we may modify the meaning of “left” with respect to the ordering of subterms.

The first fix involves replacing the term constructors [·, ·]·, it_{μF} ··, and (λ⌊·⌋. ·)· with the following, two of which we have used (slightly modified) as abbreviations:

(+ Elim′)  \frac{Γ ▷ M: σ + τ, Γ ▷ P: σ→υ, Γ ▷ Q: τ→υ}{Γ ▷ case M of P, Q: υ}

(μ Elim′)  \frac{Γ ▷ M: μF, Γ ▷ N: F (τ)→τ}{Γ ▷ induct_{μF}^{τ} MN: τ}

(⊥ Elim′)  \frac{Γ ▷ M: σ_{⊥}, Γ, x: σ ▷ N: τ}{Γ ▷ let ⌊x: σ⌋ = M in N: τ} τ pointed.

The previously non-left-normal reduction rules now become

(+β_{1})′_{r} case ι_{1}N of P, Q ⟶ P N

(+β_{2})′_{r} case ι_{2}N of P, Q ⟶ QN

(μβ)′_{r} induct_{μF} (fold_{μF} P)N ⟶ N(F (λx: μF. induct_{μF} xN)P)

(⊥β)′_{r} let ⌊x: σ⌋ = ⌊P ⌋ in N ⟶ {P/x}N

(⊥β′)′_{r} let ⌊x: σ⌋ = ⊥ in N ⟶ ⊥,

which are all left-normal.

The other solution is to modify the left-to-right order of evaluation by altering the definition of when one redex, R, is to the left of another, S, written R ≺ S. The effect of this will be to direct reduction into the appropriate part of a potential redex (for example, the test P of a choice expression [M, N]P) so that the reduction does not get needlessly sidetracked. The definition of R ≺ S that we start with is that a subterm R of a term M (which we write R ⊆ M; if R ≢ M then as usual we write R ⊂ M) is to the left of another subterm S ⊆ M if one of the following conditions holds:

• S ⊂ R;

• R ⊆ M_{1} and S ⊆ M_{2} for some subterm [M_{1}, M_{2}] of M;

• R ⊆ M_{1} and S ⊆ M_{2} for some subterm ⟨M_{1}, M_{2}⟩ of M; or

• R ⊆ M_{1} and S ⊆ M_{2} for some subterm M_{1}M_{2} of M.

Our modification will be to the last clause, based on whether or not the term M_{1} is a strict abstraction, choice, or iterated function:

• if R ⊆ M_{1} and S ⊆ M_{2} for some M_{1}M_{2} ⊆ M, then R ≺ S if M_{1} ≢ (λ⌊x: σ⌋. P), [P, Q], or it_{μF} P, otherwise S ≺ R.

Now, following Klop, we may define standard reductions and the process of standardization. If we have a reduction sequence R: M_{0} ⟶ M_{1} ⟶ …, then let us form a labelled sequence by the following process: if the redex contracted in the term M_{i} is R, then we label every redex S ≺ R; descendents of labelled redexes keep their labels until they are themselves reduced. For example, here is the labelled form of a reduction from a term discussed above:

[id, fix id](id(ι_{1}◇))^{∗} ⟶ [id, id(fix id)](id(ι_{1}◇))^{∗}
⟶ ([id, id(fix id)](ι_{1}◇))^{∗}
⟶ ([id, fix id](ι_{1}◇))^{∗}
⟶ id ◇
⟶ ◇.

A standard reduction is one in which no labelled redexes are contracted. The above reduction is not standard because two labelled redexes contract, producing the second and fourth lines respectively. An equivalent standard reduction is

[id, fix id](id(ι_{1}◇)) ⟶ [id, fix id](ι_{1}◇)
⟶ id ◇
⟶ ◇.

An anti-standard pair of reduction steps is a reduction R_{1}: M_{0} ⟶ M_{1} ⟶ M_{2} which is not standard. The process of meta-reduction is the replacement in a reduction R of an anti-standard pair R_{1} by an equivalent standard reduction R_{2} to obtain a new reduction R′; we write R ⟹ R′. For example, in the reduction sequence

R: (λx: σ. id⟨x, x⟩)(id ◇) ⟶ (λx: σ. id⟨x, x⟩)◇ ⟶ id⟨◇, ◇⟩ ⟶ ⟨◇, ◇⟩,

the first two reduction steps form an anti-standard pair; the pair may be replaced by a standard reduction to obtain the reduction sequence

R′: (λx: σ. id⟨x, x⟩)(id ◇) ⟶ id⟨id ◇, id ◇⟩ ⟶ id⟨◇, id ◇⟩
⟶ id⟨◇, ◇⟩ ⟶ ⟨◇, ◇⟩,

which is intuitively closer to a standard reduction than R. One can imagine how repeating this process of meta-reduction will eventually produce a standard reduction sequence.

This intuition is formalized by the following theorem:

Theorem 4.3.3 (Standardization) For every λ_{r}^{⊥ρ} reduction sequence R: M ⟶ N there is a standard reduction sequence R_{st}: M ⟶ N, obtained as a normal form of meta-reduction.

Proof. See [28], Section II.6.2.8. In fact, Klop does not give the proof for the fully general case of a left-normal regular combinatory reduction system, he only indicates that it is possible. However, a minor modification to λ_{r}^{⊥ρ} will put it in the form of a left-normal term rewriting system plus lambda abstraction, for which Klop does provide a full proof. The required change is that the binding operation of strict abstraction (λ⌊x: σ⌋. M) be replaced by the ordinary lambda abstraction (λz: σ_{⊥}. test_{σ}^{τ}z(λx: σ. M)), where test_{σ}^{τ}: σ_{⊥}→(σ→τ)→τ is a new function constant. The action of test_{σ}^{τ} is given by the following reduction rules:

test_{σ}^{τ}⌊M⌋N ⟶ NM
test_{σ}^{τ}⊥N ⟶ ⊥;

that is, it strictly evaluates the first argument and then applies the second argument to the result. It is easy to see that this modified system will have essentially the same reduction behavior as λ_{r}^{⊥ρ}; in particular, the standard reductions in the two systems will be isomorphic.

As a corollary we find that a leftmost strategy for λ_{r}^{⊥ρ} is normalizing, either using the straight definition of “left” and the modified syntax or using the adjusted definition of “left” and the original syntax:

Corollary 4.3.4 (Normalization) If there is a λ_{r}^{⊥ρ} reduction M ⟶ N where N is a normal form, then the reduction sequence starting at M in which the leftmost redex is contracted at each step will eventually reach N.

Proof. By the Standardization theorem, there is a standard reduction R_{st} from M to N. Suppose that there is some step in R_{st} in which the contracted redex is not leftmost; then since the reduction is standard, no descendents of the redexes to the left can ever be contracted, nor can they be erased, hence N must contain uncontracted redexes, contradicting the fact that it is a normal form. Therefore R_{st} is the desired normal reduction sequence.

Note that this result is weaker than the computational adequacy results of the previous two chapters. If there is some reduction from a term to a normal form then we are guaranteed to find it, but there is no guarantee that the reduction system is strong enough to produce a normal form whenever the initial term is provably equal to one. Indeed, consider the term fix^{σ} id^{σ}; it is provably equal to ⊥^{σ}, but there is no λ_{r}^{⊥ρ} reduction between these terms. The reason for this is that we added several ad hoc proof rules, such as fixed point induction and reasoning by cases for lifted types, which were necessary to get a strong enough proof system but which were not categorically motivated. It is a subject of future research to find categorically-based proof rules which permit similarly powerful arguments about programs and which are better-behaved than the ad hoc rules given here.

4.4 Example: call-by-name and call-by-value

One historical motivation for adding the capability to solve mixed-variant RDEs is the desire to find models for the untyped lambda calculus, Λ. That is, we wish to have a type u of untyped lambda terms, along with a translation U into a typed calculus such that U(M) is a term of type u that has the same behavior (in some sense) as the untyped term M.

A first attempt to model Λ in λ^{⊥ρ} might take u ≡ ρt. t→t; this would allow us to translate the application MN as unfold_{u} U(M)U(N). Unfortunately, since 1 ≅ 1→1 and 1 is initial in CPPO^{R}, the interpretation of u is just the trivial cpo. The usual semantic approach is to build the fixed point on top of a domain which has some non-trivial structure to begin with (see for example [20, 51]). We may use a much simpler syntactic reformulation to avoid the trivial solution by explicitly introducing extra structure with lifting. The result we will discuss in this section is that two particularly obvious choices for u using lifting correspond to callby-name and call-by-value versions of Λ (see [42] for the original discussion of call-by-name and call-by-value; a presentation of domain models for these calculi which are essentially the same as the types n and v below is in [5]).

The type n ≡ ρt. (t→t)_{⊥} adds to u the structure representing the possibility that a term might be undefined after an unfolding. Unfolding a term of type n will correspond to getting the head of an application into the form of an abstraction; evaluating the head may not terminate, and the bottom element takes care of this possibility. If we do get the head into the form of an abstraction, then that corresponds to obtaining the lift of a function of type n→n after the unfolding. Such a function will necessarily produce a term of type n when applied to any argument of type n — it does not need to perform any extra evaluation on the argument; for this reason, the type n corresponds to a call-by-name calculus.

By contrast, the type v ≡ ρt. t→t_{⊥} will correspond to a call-by-value calculus, because once the head has unfolded to a function, it is only a partial function (by the standard interpretation of v→v_{⊥} as the type of partial functions from v to v); the result of application may not terminate. Since we also have the possibility that simply trying to get the head of the application into abstraction form may not terminate, the type we will actually use to model terms of the call-by-value calculus is v_{⊥}.

To put this discussion in more concrete terms, consider the following translations from Λ to λ^{⊥ρ}:

N (x) ≡ x: n
N (λx. M) ≡ fold_{n}⌊λx: n. N (M)⌋: n
N (MN) ≡ App^{N} N (M)N (N): n
V(x) ≡ ⌊x⌋: v_{⊥}
V(λx. M) ≡ ⌊fold_{v}(λx: v. V(M))⌋: v_{⊥}
V(MN) ≡ App^{V} V(M)V(N): v_{⊥},

where App^{N} ≡ (λ fold_{n}⌊f: n→n⌋. f) and App^{V} ≡ (λ⌊fold_{v}(f: v→v_{⊥})⌋. λ⌊z: v⌋. fz) (recall that, in our pattern matching syntax, (λ fold_{τ} P. M) is shorthand for the term (λx: τ. (λP. M)(unfold_{τ} x))). In evaluating an application MN in either call-by-name or call-by-value, M must first reduce to an abstraction. The strict abstractions on f in the App combinators will ensure that this evaluation takes place first. In the case of the call-by-value translation, the additional strict abstraction on z forces the evaluation of the argument next; in call-by-name, the function f is simply applied to the argument right away.

To formalize the connection with the call-by-name and call-by-value calculi, recall from [42] that the reductions ⟶^{cbn} and ⟶^{cbv} are built up from the axioms

(β) (λx. M)N ⟶ {N/x}M

(β_{V}) (λx. M)V ⟶ {V/x}M, V a value,

respectively, where a value is either a variable or an abstraction (we will omit the optional set of constants and δ-rules for simplicity). Then we may prove the following theorem:

Theorem 4.4.1 M ⟶^{cbn} N iff N (M) ⟶ N (N), and M ⟶^{cbv} N iff V(M) ⟶ V(N).

Proof. The forward direction of each part proceeds by induction on the length of the reduction; we only need to show that N ((λx. M)N) ⟶ N ({N/x}M) and V((λx. M)V) ⟶ V({V/x}M), for V a value. We will only show the details of the second, since the first is very similar (and easier):

V((λx. M)V) ≡ App^{V} ⌊fold_{v}(λx: v. V(M))⌋V(V)
⟶ (λ⌊z: v⌋. (λx: v. V(M))z)V(V);

since V is a value, V(V) must be of the form ⌊N⌋ for some term N, hence the strict application may reduce, leading to {N/x}V(M). Now, examination of the definition of V(M) reveals that this substitution is identical to the term V({V/x}M), as desired.

In the other direction we will make use of the standardization theorem of the previous section. Again, we will only give the details for the more complex call-by-value case. We will proceed by induction on the structure of M and the length of the reduction sequence. If M ≡ x, then V(M) ≡ ⌊x⌋, which is a normal form, so M ≡ N and we are done. If M ≡ (λx. P), then V(M) ≡ ⌊fold_{v}(λx: v. V(P))⌋, so the only possible reduction is to ⌊fold_{v}(λx: v. Q)⌋. For this to be V(N) we must have that Q ≡ V(P′) for N ≡ (λx. P′); by the induction hypothesis then we know that P ⟶^{cbv} P′ and hence M ⟶^{cbv} N.

The remaining case is that M ≡ P Q. If V(M) ≡ App^{V} V(P)V(Q) reduces to V(N), then either V(N) ≡ App^{V} V(P′)V(Q′), whence M ⟶^{cbv} P′Q′ ≡ N by the induction hypothesis, or the App^{V} must participate in the reduction. For this to be true, the standardization of the reduction must look like the following:

App^{V} V(P)V(Q) ⟶ App^{V} ⌊fold_{v}(λx: v. V(P′))⌋V(Q)
⟶ (λ⌊z: v⌋. (λx: v. V(P′))z)V(Q)
⟶ (λ⌊z: v⌋. (λx: v. V(P′))z)⌊Q_{1}⌋
⟶ {Q_{1}/x}V(P′) ≡ V({Q′/x}P′)
⟶ V(N),

where V(Q′) ≡ ⌊Q_{1}⌋. This uses the fact that in any standard reduction from V(Q), the first term in the reduction sequence which is of the form ⌊Q_{1}⌋ must in fact be V(Q′) for some value Q′. By the induction hypothesis we thus have the corresponding reduction sequence

M ≡ P Q ⟶^{cbv} (λx. P′)Q
⟶^{cbv} (λx. P′)Q′
⟶^{cbv} {Q′/x}P′
⟶^{cbv} N.

4.5 Comparison of recursive types

In this section we will prove the results mentioned in the introduction to this chapter about the relations between the recursive types in the cpo model. Although we only treat the case of CPO, we believe that the relations hold in many similar categories. A more abstract account is given by Barr [2], who shows that the initial and terminal fixed points of a functor F will coincide under fairly general conditions on F; he refers to such functors as algebraically compact. For the specific case of CPO, Barr’s theorem proves that all of our pointed functors are algebraically compact, therefore μF ≅ νF. This is one part of our result below, which we obtained independently. Fokkinga and Meijer [13] also establish a similar result, although since they only work with pointed types they find that the initial and terminal fixed points always correspond (for suitably continuous functors).

We have already described how to construct μF and νF in the category CPO, and how we may use the Smyth-Plotkin technique to construct ρF in the category CPO^{R} of retracts. Now let us use the names of terms in λ^{⊥ρ} to represent the actual functions on cpo’s which model them. For example, if we have constructed the cpo μF, then we have an isomorphism fold_{μF}: F (μF)→μF. Also, although we did not introduce the terms into our language, let us use it_{ρF}: (F (τ)→τ)→ρF →τ for the map which describes the fact that ρF is an initial F -algebra in CPO^{R}, and similarly for new_{ρF}: (τ→F (τ))→τ→ρF.

Theorem 4.5.1 If νF is pointed, then νF ≅ ρF; if μF is pointed, then μF ≅ νF ≅ ρF.

Proof. If νF is pointed, then the isomorphism unfold_{νF} and its inverse fold_{νF} provide a retract in CPO^{R} both from νF to F (νF) and also from F (νF) back to νF. Therefore we have retracts it_{ρF} fold_{νF} and new_{ρF} unfold_{νF} going both ways between νF and ρF. If there are two cpo’s X and Y and each has a retract into the other, then they must be isomorphic, hence νF and ρF are isomorphic types.

Similarly we may show that if μF is pointed then it is isomorphic to ρF. Now, since μF pointed implies νF pointed, we must have in this case that all three recursive types are isomorphic.

As an application of this theorem, we will provide an informal semantic justification of our definition in Section 4.1 that inductive and projective types will be well-formed if the body is covariant in the bound type variable and if every occurrence of the bound variable to the left of an arrow is contained in a pointed subexpression. The base case is that either the body is strictly positive, so there will be no cardinality problems to prevent us from constructing the limit or colimit essentially as we would in Set, or the body is pointed, in which case the above theorem shows that we could just as well have used the Smyth-Plotkin construction to form the retractive type.

To form an arbitrary inductive type μF (or a projective type νF) we may first decompose the body into a strictly positive context σ[ ] and a sequence of pointed type expressions τ_{1}, …, τ_{n} in which the type variable t may occur to the left of an even number of arrows. Thus F (t) ≡ σ[τ_{1}, …, τ_{n}]. Now, by a standard equivalence for recursive types, we know that μt. F (t) ≅ μt. μs. σ[{s/t}τ_{1}, τ_{2}, …, τ_{n}], where s is a new type variable. Unfolding the inner inductive type once results in the type expression μt. σ[{μs. σ[τ′_{1}, τ_{2}, …, τ_{n}]/s}τ′_{1}, τ_{2}, …, τ_{n}], where τ′_{1} ≡ {s/t}τ_{1}.

By considering the unfoldings of the inner expression {μs. σ[τ′_{1}, τ_{2}, …, τ_{n}]/s}τ′_{1}, we may see that it is equivalent to the type μr. {σ[r, τ_{2}, …, τ_{n}]/s}τ′_{1}; let us call this υ_{1}. Note that since τ_{1} was pointed, this type will also be pointed, hence we could have constructed it with ρ instead of μ. Now, repeating this process for τ_{2} through τ_{n}, we find that μt. F (t) ≅ μt. σ[υ_{1}, …, υ_{n}], where υ_{k} ≡ μr. {σ[υ_{1}, …, υ_{k−1}, r, τ_{k+1}, …, τ_{n}]/t}τ_{k}. The body of this type is strictly positive in t, and each υ_{k} is pointed, so it is a well-formed inductive type.

As an example of this construction, consider the type μt. ((t→bool)→bool)_{⊥} + t. It is equivalent to μt. υ + t, where υ ≡ μr. (((r + t)→bool)→bool)_{⊥}, which can be seen to correspond to a “partial” unfolding of the body to bring the pointed subterm to the outside.

Conclusions

We have considered three functional programming languages based on the typed lambda calculus plus structured data types and recursive definitions of either functions or types. For each we have presented an equational proof system which includes extensional rules for reasoning about equivalences of types, as well as sets of reduction rules based on the equations. We have seen the interaction of recursion with the extensional rules, and in each case we have determined that an appropriate reduction system for evaluating the results of programs should not include the extensional rules.

One of our languages, λ^{μν}, considered in Chapter 3, could define only total functions; we showed that the class of definable functions properly includes those that are provably total in Peano Arithmetic. The other two languages, PCF and λ^{⊥ρ}, considered in Chapters 2 and 4 respectively, are each powerful enough to express all partial recursive functions. We proved for both of these languages that, under certain conditions, a leftmost reduction strategy is complete for finding normal forms relative to the “ideal” non-deterministic reduction system.

For the language PCF, we obtained a confluent reduction system for any set of confluent, left-linear algebraic rules defining the set of observable types. This reduction system is adequate for finding results of programs, relative to provability in the full equational proof system, including the extensional rules. Since the interaction of the surjective pairing contraction rule with the fixed-point operator causes confluence to fail even without any algebraic rules, this result provides a theoretical basis for the folkloric belief that the extensional rules are not “computational.” In addition, we showed that the extensional rules remain sound for reasoning about observational congruence.

We did not manage to prove such an adequacy theorem for λ^{⊥ρ}; the difficulty came in having to deal with several ad hoc proof rules for retractive and lifted types. For the sublanguage λ^{μν}, where all of the proof rules had clear categorical motivations, however, we were able to prove an adequacy theorem. A future line of research is to investigate alternative proof systems for languages similar to λ^{⊥ρ} for which we can establish adequacy.

We did prove a standardization theorem for λ^{⊥ρ}, which allowed us to investigate use of the lifted and retractive types to model call-by-name and call-by-value versions of the untyped lambda calculus. A question which we did not have time to pursue is whether we can also model the partial lambda calculus of Moggi [36] in this manner.

Other open problems which remain are to find a more exact characterization of the functions definable in λ^{μν}, to extend the class of algebraic rules which support a leftmost reduction strategy for PCF, and to examine the effect of adding computational monads other than lifting to λ^{⊥ρ} in the manner of Moggi and Wadler [37, 54].

Bibliography

[1] H.P. Barendregt. The Lambda Calculus: Its Syntax and Semantics. North-Holland, 1984.

[2] M. Barr. Algebraically compact functors. Manuscript, 1991.

[3] G. Berry and P.L. Curien. Sequential algorithms on concrete data structures. Theoretical Computer Science, 20:265–321, 1982.

[4] C. Böhm and A. Berarducci. Automatic synthesis of typed Λ-programs on term algebras. Theoretical Computer Science, 39:135–154, 1985.

[5] G. Boudol. Lambda-calculi for (strict) parallel functions. Technical Report 1387, INRIA, January 1991.

[6] V. Breazu-Tannen. Combining algebra and higher-order types. In Third Annual IEEE Symposium on Logic in Computer Science, pages 82–90, 1988.

[7] V. Breazu-Tannen and J.H. Gallier. Polymorphic rewriting conserves algebraic strong normalization and confluence. In G. Ausiello, M. Dezani-Ciancaglini, and S. Ronchi Della Rocha, editors, 16th International Colloquium on Automata, Languages, and Programming, volume 372 of Lecture Notes in Computer Science, pages 137–159. Springer-Verlag, 1989.

[8] W. Buchholz and S.S. Wainer. Provably computable functions and the fast growing hierarchy. In S.G. Simpson, editor, Logic and Combinatorics, volume 65 of Contemporary Mathematics, pages 179–198. American Mathematical Society, 1987.

[9] A. Church. The Calculi of Lambda Conversion. Princeton University Press, 1941. Reprinted 1963 by University Microfilms Inc., Ann Arbor, MI.

[10] E.A. Cichon and S.S. Wainer. The slow-growing and the Grzegorczyk hierarchies. Journal of Symbolic Logic, 48(2):399–408, 1983.

[11] T. Coquand and C. Paulin. Inductively defined types. In P. Martin-Löf and G. Mints, editors, COLOG-88, volume 417 of Lecture Notes in Computer Science, pages 50–66. Springer-Verlag, 1990.

[12] R.L. Crole and A.M. Pitts. New foundations for fixpoint computations. In Fifth Annual IEEE Symposium on Logic in Computer Science, pages 489–497, 1990.

[13] M.M. Fokkinga and E. Meijer. Program calculation properties of continuous algebras. Technical Report CS-R9104, CWI, January 1991.

[14] P. Freyd. Recursive types reduced to inductive types. In Fifth Annual IEEE Symposium on Logic in Computer Science, pages 498–507, 1990.

[15] J.H. Gallier. What’s so special about Kruskal’s theorem and the ordinal Γ_{0}? A survey of some results in proof theory. Annals of Pure and Applied Logic, 53(3):199–260, 1991.

[16] J.-Y. Girard. Une extension de l’interpretation de Gödel à l’analyse, et son application à l’élimination des coupures dans l’analyse et la théorie des types. In J.E. Fenstad, editor, Second Scandinavian Logic Symposium, pages 63–92. North-Holland, 1971.

[17] J.-Y. Girard, Y. Lafont, and P. Taylor. Proofs and Types. Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 1989.

[18] K. Gödel. Über eine bisher noch nicht benützte Erweiterung des finiten Standpunktes. Dialectica, 12:280–287, 1958. An English translation by W. Hodges and B. Watson appeared in Journal of Philosophical Logic, 9:133–142, 1980.

[19] J. Greiner. Programming with inductive and co-inductive types. Technical Report CMU-CS-92-109, Carnegie Mellon University, January 1992.

[20] C.A. Gunter and D.S. Scott. Semantic domains. In J. van Leeuwen, editor, Handbook of Theoretical Computer Science. North-Holland, 1990.

[21] T. Hagino. A Categorical Programming Language. PhD thesis, University of Edinburgh, 1987.

[22] T. Hagino. A typed lambda calculus with categorical type constructors. In Category Theory in Computer Science, pages 140–157, 1987.

[23] J.Y. Halpern, J.H. Williams, E.L. Wimmers, and T.C. Winkler. Denotational semantics and rewrite rules for FP. In 12th ACM Symposium on Principles of Programming Languages, pages 108–120, January 1985.

[24] R. Hasegawa. Parametric polymorphism and internal representations of recursive type definitions. Master’s thesis, Research Institute for Mathematical Science, Kyoto University, 1989.

[25] P. Henderson. Functional Programming. Prentice-Hall, 1980.

[26] B.T. Howard and J.C. Mitchell. Operational and axiomatic semantics of PCF. In ACM Conference on Lisp and Functional Programming, pages 298–306, 1990.

[27] C.B. Jay. Long βη normal forms and confluence. Technical Report ECS-LFCS-91-183, Laboratory for Foundations of Computer Science, Department of Computer Science, University of Edinburgh, October 1991.

[28] J.W. Klop. Combinatory Reduction Systems. PhD thesis, University of Utrecht, 1980. Published as Mathematical Center Tract 129.

[29] J.W. Klop and R.C. de Vrijer. Unique normal forms for lambda calculus with surjective pairing. Information and Computation, 80(2):97–113, 1989.

[30] G. Kreisel. Interpretation of analysis by means of constructive functionals of finite types. In A. Heyting, editor, Constructivity in Mathematics, pages 101–128. North-Holland, 1959.

[31] J. Lambek and P.J. Scott. Introduction to Higher-Order Categorical Logic, volume 7 of Cambridge Studies in Advanced Mathematics. Cambridge University Press, 1986.

[32] S. Mac Lane. Categories for the Working Mathematician, volume 5 of Graduate Texts in Mathematics. Springer-Verlag, 1971.

[33] Z. Manna, S. Ness, and J.E. Vuillemin. Inductive methods for proving properties of programs. In ACM Conference on Proving Assertions about Programs, pages 27–50, 1972. Proceedings appeared as SIGPLAN Notices, 7(1), 1972.

[34] L.W. Miller. Normal functions and constructive ordinal numbers. Journal of Symbolic Logic, 41(2):439– 459, 1976.

[35] J.C. Mitchell. Type systems for programming languages. In J. van Leeuwen, editor, Handbook of Theoretical Computer Science. North-Holland, 1990.

[36] E. Moggi. The Partial Lambda-Calculus. PhD thesis, University of Edinburgh, 1988.

[37] E. Moggi. Computational lambda-calculus and monads. In Fourth Annual IEEE Symposium on Logic in Computer Science, pages 14–23, 1989.

[38] D. Nesmith. The Church-Rosser property in higher-order rewrite systems. Manuscript, 1989.

[39] M.H.A. Newman. On theories with a combinatorial definition of “equivalence”. Annals of Mathematics, 43(2):223–243, 1942.

[40] S.L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice-Hall, 1987.

[41] G.D. Plotkin. The λ-calculus is ω-incomplete. Journal of Symbolic Logic, 39:313–317, 1974.

[42] G.D. Plotkin. Call-by-name, call-by-value and the λ-calculus. Theoretical Computer Science, 1:125–159, 1975.

[43] G.D. Plotkin. LCF considered as a programming language. Theoretical Computer Science, 5:223–255, 1977.

[44] G.D. Plotkin. Denotational semantics with partial functions. Lecture notes, C.S.L.I. Summer School, Stanford, 1985.

[45] G. Pottinger. The Church-Rosser theorem for typed λ-calculus with surjective pairing. Notre Dame Journal of Formal Logic, 22(3):264–268, 1981.

[46] J.C. Reynolds. Towards a theory of type structure. In Paris Colloquium on Programming, volume 19 of Lecture Notes in Computer Science, pages 408–425. Springer-Verlag, 1974.

[47] H.E. Rose. Subrecursion: Functions and Hierarchies, volume 9 of Oxford Logic Guides. Oxford University Press, 1984.

[48] H. Schwichtenberg. Elimination of higher type levels in definitions of primitive recursive functions by means of transfinite recursion. In H.E. Rose and J.C. Shepherdson, editors, Logic Colloquium, ’73, pages 279–303. North-Holland, 1975.

[49] H. Schwichtenberg. Definierbare funktionen im λ-Kalkül mit typen. Archiv für mathematische Logik und Grundlagenforschung, 17:113–114, 1976.

[50] D.S. Scott. A type-theoretic alternative to CUCH, ISWIM, OWHY. Manuscript, 1969.

[51] M. Smyth and G.D. Plotkin. The category-theoretic solution of recursive domain equations. SIAM Journal on Computing, 11:761–783, 1982.

[52] R. Statman. The typed lambda calculus is not elementary recursive. Theoretical Computer Science, 9:73–81, 1979.

[53] D.A. Turner. Miranda: a non-strict functional language with polymorphic types. In IFIP International Conference on Functional Programming and Computer Architecture, Nancy, volume 201 of Lecture Notes in Computer Science. Springer-Verlag, 1985.

[54] P. Wadler. Comprehending monads. In ACM Conference on Lisp and Functional Programming, pages 61–78, 1990.

[55] P. Wadler. Private communication, March 1991.

[56] S.S. Wainer. Slow growing versus fast growing. Journal of Symbolic Logic, 54(2):608–614, 1989.

[57] M. Wand. Fixed-point constructions in order-enriched categories. Theoretical Computer Science, 8:13– 30, 1979.

[58] G.C. Wraith. A note on categorical datatypes. In D.H. Pitt, D.E. Rydeheard, P. Dybjer, A.M. Pitts, and A. Poigné, editors, Category Theory and Computer Science, volume 389 of Lecture Notes in Computer Science, pages 118–127. Springer-Verlag, 1989.