Lectures onType Theory
Chapter 9
Chapter 9Core route

System F, Impredicativity, and Normalization

Hindley–Milner polymorphism gives a let-bound variable a fresh monotype at each use. It does not make a polymorphic value into an ordinary argument. Three pieces of notation make that missing operation visible. The type X.A describes a term that works at every type X; the term ΛX.t abstracts over that type; and t[A] supplies the type A to such an abstraction. The following display retains its annotations so that the three roles remain visible: (λf:I.f[I]f)(ΛX.λx:X.x),I:=X.XX. The right-hand argument is the polymorphic identity. Inside the left-hand abstraction, the parameter f is first instantiated at the polymorphic type I and then applied to itself. This is self-application, not recursion. Its three beta steps are: the outer lambda substitutes the identity for f, the type application substitutes I for X, and the remaining lambda λx:I.x substitutes the identity for x and returns it. Nevertheless its erasure cannot be typed by Algorithm W of definition 3.28. A lambda-bound variable has one monotype α there, and typing ff demands α=αβ, which fails the occurs check.

The remedy is to make abstraction over a type, and application to a type, part of the term language. In the annotated, or Church-style, calculus, those two operations remain in the term. Its annotations make checking syntax directed and its reductions make the opening calculation literal. Under Curry–Howard, types are propositions and terms are proofs. The logic is second-order because the formula X.A quantifies over a proposition—represented here by the type variable X—rather than over an element of one fixed domain. Type abstraction introduces that quantified variable, and type application eliminates its universal quantifier.

The metatheory consists of mathematical statements about System F syntax, typing, and reduction, rather than formulas expressed inside System F. Unless a result states a smaller base theory, this chapter proves its metatheorems in classical ZF set theory. Finite syntax carries a fixed numerical coding. A Turing machine has finitely many states and tape symbols, an unbounded tape with one symbol under a read–write head, and a finite table that specifies the symbol to write, the next state, and the head’s next move. It computes an output when it halts. Accordingly, an “algorithm” here is such a machine that halts on every stated input code, and an “effective” translation is the total map on codes that it computes.

The Church-style calculus

Two sorts of variables

System F has term variables x,y,z, and type variables X,Y,Z,. Confusing their two substitutions is a reliable way to make the universal rules look simpler than they are. We therefore keep separate contexts from the beginning.

Definition 5.1 — Types and annotated terms

An annotated term records the type at every term binder and records each type abstraction and application explicitly. The types and these Church-style terms of System F are A,B::=XABX.A,t,u::=xλx:A.ttuΛX.tt[A]. The dots delimit binder scope: X binds X in A; λx:A binds x in t; and ΛX binds X in every type annotation and type argument occurring in t.

Thus λx:X.x has the type variable X free, whereas ΛX.λx:X.x does not. The expression ΛX.λx:Y.x is syntactically legal. If Y has been declared available as a type variable, the expression has type X.YY. With no available type variables it is not typable, because the annotation Y refers to an undeclared name. Syntax alone does not supply the missing scope.

Convention 5.2 — Binding and substitution

Apply the named-variable binding construction of convention 2.3 separately to the two sorts. Official types and terms are alpha-equivalence classes. Write ftv(A) and ftv(t) for free type variables, and fv(t) for free term variables; structural recursion over the grammar forms these sets, and each binder removes its bound name from the corresponding set. We write A[B/X] and t[B/X] for capture-avoiding type substitution, and t[u/x] for capture-avoiding term substitution. Type substitution descends into annotations and type arguments; term substitution does not change a type. Before substituting, all obstructing binders are freshened away from the free variables of the substituend.

For a finite map θ from distinct type variables to types, write A[θ] and t[θ] for simultaneous capture-avoiding type substitution in one pass. At a type variable in the domain, the operation returns its image without recursively substituting into that image; it is homomorphic at every other constructor after obstructing binders have been freshened. When all images are closed, the result agrees with successive single substitutions in any order. Thus the operation is independent of an enumeration of the finite map and of the chosen fresh binder representatives.

Square brackets consequently have two jobs: in t[A] they are part of the term syntax, while in t[B/X] they denote the metatheoretic substitution operation. The slash distinguishes the latter.

The defining clauses at the new constructors are (Y.A)[B/X]=Y.A[B/X](YX, Yftv(B)),(ΛY.t)[B/X]=ΛY.t[B/X](YX, Yftv(B)),(t[A])[B/X]=(t[B/X])[A[B/X]],(ΛX.t)[u/x]=ΛX.t[u/x],(t[A])[u/x]=t[u/x][A]. These equations determine operations on alpha-classes: rename corresponding binders to a common fresh name and induct on their bodies. The following composition equations will be used. Here XY, Xftv(C), xy, and yfv(u): A[B/X][C/Y]=A[C/Y][B[C/Y]/X](type/type on types),t[B/X][C/Y]=t[C/Y][B[C/Y]/X](type/type on terms),s[v/y][u/x]=s[u/x][v[u/x]/y](term/term),t[u/x][C/X]=t[C/X][u[C/X]/x](term/type). In the last line lowercase x is a term variable and uppercase X is a type variable. Bound variables are chosen fresh up to alpha-equivalence. These equations follow by simultaneous induction on types and terms; the binder cases use exactly the synchronization argument just described.

The type-application substitution clause deserves attention. Substituting B for X in t[A] changes both the operator t and the supplied type A. Choose C with a free Y, where Y differs from X. Choose a type variable Z fresh for C and different from X. Renaming Y to Z prevents the type binder from capturing the free Y of C. The alpha-renaming and substitution steps are ((ΛY.λy:X.y)[X])[C/X]=((ΛZ.λy:X.y)[X])[C/X](α),=(ΛZ.λy:C.y)[C](substitution). Changing only the annotation in the lambda, or only the argument of the type application, would not define substitution on this syntax.

Exercise 5.1

★★★ Let XY and Xftv(C). Calculate both sides of t[B/X][C/Y]=t[C/Y][B[C/Y]/X] by induction on t. Treat a ΛZ case in which its representative’s binder occurs in B or C: choose a common fresh replacement and show the freshening step rather than silently renaming it.

Formation and typing

Definition 5.3 — Contexts

A type-variable context Δ is a finite list of distinct type variables. A term context Γ is a finite list of distinct declarations x:A. For either kind of context, dom is the set of names listed in it. The judgments Δ typectx and ΔΓ ctx are generated by

 typectx
F-Δ-Emp
Δ typectxXΔ
Δ,X typectx
F-Δ-Ext
Δ typectx
Δ ctx
F-Γ-Emp
ΔΓ ctxΔA typexdom(Γ)
ΔΓ,x:A ctx
F-Γ-Ext

Every type in Γ is therefore formed using variables already in Δ. In particular, if X is fresh for Δ, then it is absent from every type in Γ.

Definition 5.4 — Type formation and Church typing

Type formation is generated by

XΔ
ΔX type
F-Ty-Var
ΔA typeΔB type
ΔAB type
F-Ty-Arr
Δ,XA typeXΔ
ΔX.A type
F-Ty-All

For well-formed Δ and Γ, term typing is generated by

x:AΓ
Δ;Γx:A
F-Var
Δ;Γ,x:At:B
Δ;Γλx:A.t:AB
F-Arr-I
Δ;Γt:ABΔ;Γu:A
Δ;Γtu:B
F-Arr-E
Δ,X;Γt:AXΔ
Δ;ΓΛX.t:X.A
F-All-I
Δ;Γt:X.AΔB type
Δ;Γt[B]:A[B/X]
F-All-E

Every displayed typing judgment Θ;Γt:A presupposes Θ typectx, ΘΓ ctx, and ΘA type. This applies to every premise and conclusion of F-VarF-All-E. In the premise of F-All-I, Θ=Δ,X; type-context weakening derives Δ,XΓ ctx from ΔΓ ctx. The weakening, term-substitution, and type-substitution lemmas retain all three formation derivations when they rebuild a typing rule.

Rule F-All-I does not need a separate side condition Xftv(Γ). Its premise uses the unchanged context Γ, which was already formed under Δ; context formation gives that freshness. If one allowed arbitrary unformed contexts, the rule would be unsound. For instance, the tempting derivation of ΛX.x:X.X from x:X cannot even begin with a context x:X formed under the empty type context. The obstruction occurs before typing: x:X ctx,so there is no premise from which F-All-I can bind X. If the unformed declaration were admitted, the locally bound type name would escape through the unchanged declaration of x. This is a scope error, not a closed program whose evaluation happens to get stuck.

Now type the opening term. Put id:=ΛX.λx:X.x,d:=λf:I.f[I]f. The identity has the derivation x:Xx:XX;x:Xx:XFVarX;λx:X.x:XXFArrI;id:IFAllI. For the body of d, universal elimination at the type I gives ;f:If:X.XXI type;f:If[I]:IIFAllE. Together with f:I, arrow elimination gives f[I]f:I; hence d:II and the complete expression did has type I. The decisive step is the instantiation X:=I. An impredicative quantifier ranges over types that themselves contain the same kind of quantifier; hence the universal quantifier of System F is impredicative. A predicative design instead stratifies types into levels and permits quantification only over a lower level. The reducibility family in chapter 2 recursed on a type: its arrow clause used only the immediate component types. A universal clause would have to interpret A[B/X] for every formed B, including I; that type need not be a strict subexpression of X.A and can contain more type constructors. The subexpression recursion used in chapter 2 does not license those calls, so the normalization argument needs a different construction.

Exercise 5.2

★★☆ Write one derivation tree, with no omitted leaves, for ;did:I. Mark the two different occurrences of f in the premise of F-Arr-E, and state the type synthesized for each one.

Structural lemmas

There are two binders and therefore two substitution lemmas. Type substitution must transform the types stored in a term context; term substitution does not. Proving the easy lemma first prevents the two operations from being mixed in the preservation proof.

Lemma 5.5 — Scope and weakening

The following properties hold.

  1. If Δ;Γt:A, then ftv(t)ftv(A)dom(Δ) and fv(t)dom(Γ).

  2. If Δ;Γ0,Γ1t:A, ΔB type, and ydom(Γ0,Γ1), then Δ;Γ0,y:B,Γ1t:A. The same insertion preserves term-context formation.

  3. Let YΔ0,Δ1. Inserting Y into the type context preserves each of the following judgments: Δ0,Δ1A typeΔ0,Y,Δ1A type,Δ0,Δ1Γ ctxΔ0,Y,Δ1Γ ctx,Δ0,Δ1;Γt:AΔ0,Y,Δ1;Γt:A.

Proof of Lemma 5.5 — Scope and weakening

Proof. For item 1, induct on the typing derivation simultaneously with type and context formation. The variable leaf uses the formation derivation of its declaration. At F-All-I, the bound type variable is removed from the free-variable set in the conclusion; at F-All-E, the premise ΔB type ensures that every free variable of the type argument lies in Δ. At F-Arr-I, the induction hypothesis bounds the body’s free variables, while formation of Γ,x:A gives ftv(A)dom(Δ) for the lambda annotation. These are the only binder-specific scope cases.

For item 2, induct on typing. In the variable case the old membership is unchanged. In an F-Arr-I case, alpha-rename the lambda binder away from y before applying the induction hypothesis to the premise; the extended context then retains distinct variable names. For context formation, induct on the length of the suffix Γ1. The empty suffix is immediate. If Γ1=Γ1,z:C, insert y:B before Γ1 by the induction hypothesis and then rebuild the final declaration z:C with F-Γ-Ext. For item 3, first induct on type and context formation, and then on typing. At a universal binder choose its name fresh for the inserted variable and use the induction hypothesis in the doubly extended type context. The argument uses neither a conversion rule that changes the derived type nor an exchange rule that that reorders context declarations: it constructs the weakened derivation under the extended context directly. ◻

Lemma 5.6 — Type substitution

Suppose Δ0,X,Δ1 is well formed and Δ0C type. Then:

  1. if Δ0,X,Δ1A type, then Δ0,Δ1A[C/X] type;

  2. if Δ0,X,Δ1Γ ctx, then Δ0,Δ1Γ[C/X] ctx;

  3. if Δ0,X,Δ1;Γt:A, then Δ0,Δ1;Γ[C/X]t[C/X]:A[C/X].

Proof of Lemma 5.6 — Type substitution

Proof. Type substitution preserves formation and typing. Type formation is an induction on its derivation. At a type-variable leaf, the distinguished variable becomes C and uses the weakening of its given formation derivation through Δ1; every other variable remains a variable. Arrow formation uses the two induction hypotheses. At Y.A, first choose YX fresh for C,Δ0,Δ1. The induction hypothesis applies under Y and F-Ty-All reattaches the binder. Context formation follows declaration by declaration from item 1.

For typing, induct on the final rule. The variable case uses the corresponding declaration in Γ[C/X]. Arrow introduction and elimination use the induction hypotheses, with the term binder freshened if needed. At universal introduction, display its bound variable as YX, fresh for C; apply the induction hypothesis under Δ0,X,Δ1,Y and reapply F-All-I.

The only calculation occurs at universal elimination. Its premise has t:Y.A0 and a formed argument B. After the induction hypothesis we obtain t[C/X]:(Y.A0)[C/X]=Y.A0[C/X] and B[C/X] is formed by item 1. Elimination therefore returns A0[C/X][B[C/X]/Y]. After freshening Y away from C, the substitution-composition equation of convention 5.2 gives A0[C/X][B[C/X]/Y]=(A0[B/Y])[C/X], the required conclusion. ◻

Lemma 5.7 — Term substitution

If Δ;Γ0,x:A,Γ1t:BandΔ;Γ0u:A, then Δ;Γ0,Γ1t[u/x]:B. Here the declarations in Γ1 are unchanged, because System F types do not contain term variables.

Proof of Lemma 5.7 — Term substitution

Proof. Induct on the typing derivation of t. At a variable leaf, the distinguished variable is replaced by the weakened derivation of u; another variable remains a variable. Arrow introduction first freshens its binder away from u and applies the induction hypothesis under the extended context. Arrow elimination applies the two hypotheses. Universal introduction freshens its type binder away from all type variables in the derivation Δ;Γ0u:A, uses lemma 5.5(3) to weaken that derivation in the new type context, and applies the induction hypothesis. Universal elimination changes only the operator term, so its induction hypothesis and the old type-formation premise reapply the rule. ◻

Exercise 5.3

★★☆ Apply lemma 5.6 to the derivation X;f:XX,x:Xfx:X with C=Y.YY. Display the transformed context and every leaf of the resulting derivation. Then explain why term substitution alone cannot perform this transformation.

Evaluation and safety

Type abstraction is computationally inert until a type is supplied. It is therefore a value, just as a term abstraction is. Type application does not inspect the run-time representation of its type argument; it merely removes an annotation-level binder.

Definition 5.8 — Call-by-value reduction

Values, evaluation contexts, and the two contractions are v::=λx:A.tΛX.t,E::=[]EtvEE[A],(λx:A.t)vt[v/x],(ΛX.t)[A]t[A/X]. The production E[A] is explicit type application under a hole, not plugging. If tt, then EtEt. No reduction takes place beneath either abstraction in this call-by-value relation. Write for its reflexive transitive closure.

The opening term now performs the promised calculation: didβid[I]idβ(λx:I.x)idβid. The type argument I leaves no run-time component.

Lemma 5.9 — Canonical forms

Let Δ;v:A and let v be a value.

  1. If A=A1A2, then v=λx:A1.t.

  2. If A=X.B, then v=ΛX.t.

Proof of Lemma 5.9 — Canonical forms

Proof. Invert the final typing rule after observing that the two type constructors and are disjoint and injective. A lambda can only end in F-Arr-I, and a type abstraction only in F-All-I; variables are impossible in the empty term context. Thus the outer constructor of the type selects the corresponding value form. ◻

Theorem 5.10 — Preservation

If Δ;Γt:A and tt, then Δ;Γt:A.

Proof of Theorem 5.10 — Preservation

Proof. Induct on the evaluation-context decomposition of the step. Congruence cases rebuild the same typing rule from the induction hypothesis. There are two redexes.

For term beta, inversion gives Δ;Γ,x:Bs:A,Δ;Γv:B. Term substitution yields Δ;Γs[v/x]:A.

For type beta, inversion gives Δ,X;Γs:B,ΔC type, where context formation entails Xftv(Γ). Type substitution, with empty trailing type context, yields Δ;Γs[C/X]:B[C/X], which is exactly the type assigned to (ΛX.s)[C] by F-All-E. ◻

Theorem 5.11 — Progress

If Δ;t:A, then either t is a value or there is a term t with tt.

Proof of Theorem 5.11 — Progress

Proof. Induct on the typing derivation. A variable case is impossible. Both introduction forms are values. For t1t2, apply the two induction hypotheses from left to right. A step in either premise gives an evaluation context step. If both are values and the operator has arrow type, canonical forms gives t1=λx:B.s, so term beta applies.

For t0[C], the induction hypothesis either steps t0, giving the context [][C], or returns a value. Its type is universal, so canonical forms gives t0=ΛX.s and type beta applies. These cases exhaust the typing rules. ◻

Corollary 5.12 — Safety

A closed well-typed Church term never reaches a closed stuck term: if ;t:A and tu, then u is a value or u takes another step.

Proof of Corollary 5.12 — Safety

Proof. Repeated preservation types u at A; progress says that u is a value or takes another step. ◻

Safety does not yet say that evaluation terminates. Progress permits an infinite sequence of well-typed steps. The strong normalization theorem later in this chapter rules those sequences out for the larger compatible beta relation, and therefore for call-by-value evaluation as well.

Exercise 5.4

★★☆ Suppose Δ;Γ(ΛX.t)[C]u:D and its left subterm takes the type-beta step. Invert the typing derivation, apply type substitution, and rebuild the final application derivation. If the body of the universal type is B, state the type B of t before substitution, the equality B[C/X]=AD forced by the outer application, and the resulting function typing of t[C/X].

Data represented by quantification

Call-by-value reduction deliberately stops beneath abstractions. Equations between encoded programs require a relation that may calculate in every subterm. We fix it before introducing the encodings.

Definition 5.13 — Compatible beta reduction

Compatible beta reduction β is the least relation containing (λx:A.t)uβt[u/x],(ΛX.t)[A]βt[A/X], and closed under all five term constructors, including the bodies of λ and Λ. Write =β for the reflexive, symmetric, transitive closure and β for the reflexive transitive closure. We also write uβv for vβu. The call-by-value relation of definition 5.8 is a subrelation of β.

The preservation proof for β repeats theorem 5.10; reducing beneath a binder uses its premise typing derivation, and the two contractions use the same substitution lemmas. We record the result because every calculation below uses it.

Proposition 5.14 — Subject reduction for compatible beta

If Δ;Γt:A and tβt, then Δ;Γt:A.

Proof of Proposition 5.14 — Subject reduction for compatible beta

Proof. Induct on the generation of the compatible step. The term- and type-beta roots are exactly the two cases of the preservation proof. For closure under application and type application, rebuild F-Arr-E or F-All-E. For closure under λ and Λ, apply the induction hypothesis in the extended term or type context and rebuild the corresponding introduction rule. Application-left, application-right, type-application, term-abstraction, and type-abstraction are precisely the compatible-context constructors. ◻

Booleans

A boolean chooses one of two continuations. The tempting monomorphic type XXX gives two selectors at one fixed X, but the same selector cannot then be used once at A and once at B. Abstracting the result type repairs precisely that failure: quantifying over the common result type makes the choice usable at every result type.

Definition 5.15 — Church booleans

Define BoolF:=X.XXX,trueF:=ΛX.λt:X.λf:X.t,falseF:=ΛX.λt:X.λf:X.f. For a formed type A, abbreviate ifA(b;u,v):=b[A]uv.

Two applications of F-Arr-I abstract the two value variables, and F-All-I then gives ;trueF:BoolF,;falseF:BoolF. If Δ;Γb:BoolF and Δ;Γu,v:A, then universal elimination followed by two arrow eliminations gives Δ;ΓifA(b;u,v):A. The computations expose all three beta steps: ifA(trueF;u,v)ββ(λt:A.λf:A.t)uvββ(λf:A.u)vββu,ifA(falseF;u,v)ββ(λt:A.λf:A.f)uvββ(λf:A.f)vββv. Call a term beta-normal when no compatible beta step applies, and call a beta-normal term variable-headed when it is built from a free term variable by term and type applications. If b is variable-headed, then b[A]uv has no beta redex at its head. The typing rules provide two branches, but do not guess which branch the variable will select. The broader technical notion needed for beta expansion is given in definition 5.24.

Exercise 5.5

★★☆ Construct closed terms notF:BoolFBoolF,andF:BoolFBoolFBoolF. Calculate notFtrueF and both cases of andFfalseFb by compatible beta reduction. Do not appeal to a primitive boolean rule.

Products and sums

A monomorphic consumer type (ABX)X fixes one result type and therefore cannot support both projections when AB. Quantifying X makes every consumer available. Dually, a sum is determined by what every pair of branch functions does with its injection.

Definition 5.16 — Church products

For formed A,B, define A×FB:=X.(ABX)X. For a:A and b:B, put a,bF:=ΛX.λk:ABX.kab. The projections are fstF;A,B(p):=p[A](λa:A.λb:B.a),sndF;A,B(p):=p[B](λa:A.λb:B.b). When p:A×FB fixes the component types, we suppress the indices and write fstF(p) and sndF(p).

The introduction derivation ends in F-All-I; its premise types kab:X under a:A,b:B,k:ABX. Universal elimination gives p[A]:(ABA)A, so the first projection has type A; the second projection is typed by instantiating at B and supplying the selector λa:A.λb:B.b:ABB. For the first beta law, fstF(a,bF)ββ(λk:ABA.kab)(λa:A.λb:B.a)ββ(λa:A.λb:B.a)abββa. The second beta law exposes the changed result type and selector: sndF(a,bF)ββ(λk:ABB.kab)(λa:A.λb:B.b)ββ(λa:A.λb:B.b)abββb.

The corresponding monomorphic sum candidate (AC)(BC)C fixes its branch result C. A value built at that type cannot later be eliminated once to C and once to a different type D. Universal quantification must therefore abstract the branch result type as well.

Definition 5.17 — Church sums

For formed A,B, define A+FB:=X.(AX)(BX)X, with introductions inlF(a):=ΛX.λf:AX.λg:BX.fa,inrF(b):=ΛX.λf:AX.λg:BX.gb, and elimination caseC(s;f,g):=s[C]fg.

If f:AC and g:BC, then caseC(s;f,g):C. The two constructor calculations are caseC(inlF(a);f,g)ββ(λf:AC.λg:BC.fa)fgββ(λg:BC.fa)gββfa,caseC(inrF(b);f,g)ββ(λf:AC.λg:BC.gb)fgββ(λg:BC.gb)gββgb.

Exercise 5.6

★★☆ Given f:AA and g:BB, construct map+:A+FBA+FB. Derive its type and calculate it on both injections. Then write the variable-headed beta-normal form obtained from map+s when s:A+FB is a variable.

The beta laws above describe constructor followed by eliminator. They do not yet supply a product uniqueness law fstF(p),sndF(p)F=βp, nor a commuting conversion that pushes an outer elimination into both branches of a variable-headed sum case. For example, such a conversion would identify q(caseC(s;f,g))withcaseD(s;λa:A.q(fa),λb:B.q(gb)). It is also useful to name the dual of a beta law. A beta law computes an eliminator applied to a constructor; an eta, or uniqueness, law reconstructs an object from all its observations. Its function and product forms are λx:A.fx=f(xfv(f)),fst(p),snd(p)=p. These equations are not generated by the beta relation of definition 5.13. Call f or p in these equations eta-short; applying the corresponding eta-expansion produces the reconstructed term on the left. The compatible beta equality =β, the symmetric transitive closure of definition 5.13, does not identify that expansion with its eta-short source. When f and p are variables, both f and λx.fx, and both p and fst(p),snd(p), are beta-normal and syntactically distinct. The encodings reproduce the constructor computations, not every judgmental equation one might choose for primitive products and sums.

Natural numbers

A natural number is an instruction to iterate an endomap—a function from a type to itself—starting at a chosen point. The monomorphic candidate A(AA)A can iterate only at its fixed carrier A. The same numeral cannot then count once in Nat and once in BoolF. Quantifying the carrier is the missing move.

Definition 5.18 — Church natural numbers

Define NatF:=X.X(XX)X,zeroF:=ΛX.λz:X.λs:XX.z,succF:=λn:NatF.ΛX.λz:X.λs:XX.s(n[X]zs),iterA(n;z,s):=n[A]zs.

The numeral and successor terms have types zeroF:NatF,succF:NatFNatF. If z:A and s:AA, then n[A]zs:A. The two iterator equations are calculations rather than additional rules: iterA(zeroF;z,s)βtypebeta,thentermbetaz,iterA(succFn;z,s)βtermbeta,typebeta,thentermbetas(iterA(n;z,s)). This is the general meaning of a Church encoding: an encoded datum is the operation that folds it. Here n[A]zs is simultaneously the eliminator and the fold of n, with algebra data z:A and s:AA. Write n for the result of applying succF to zeroF exactly n times.

Addition can now be discovered rather than guessed. To add m to n, start the m-fold iteration after the n-fold iteration has already been performed: addF:=λm:NatF.λn:NatF.ΛX.λz:X.λs:XX.m[X](n[X]zs)s. Its type is NatFNatFNatF. For example, addF12βΛX.λz:X.λs:XX.s(s(sz))β3. Notice what was proved: addition computes on displayed numerals. The term addFzeroFn expands to a type and two term abstractions around n[X]zs; beta reduction alone does not remove those abstractions when n is variable-headed. Explicitly, addFzeroFnβΛX.λz:X.λs:XX.n[X]zs, which is beta-normal when n is a variable but is not literally n.

Exercise 5.7 — *

★★★

  1. Define multiplication multF:NatFNatFNatF by iterating addition. Calculate multF23.

  2. Define step:(NatF×FNatF)(NatF×FNatF) by a,bb,succFb. Starting from zeroF,zeroF, iterate step and project the first component to obtain predF:NatFNatF. Show the reductions at zeroF and 3.

The Curry-style judgment

Erasing type abstractions and applications leaves an ordinary untyped lambda term. One can nevertheless assign System F types to that raw term by allowing universal introduction and elimination to occur in a derivation without leaving syntax behind. This is a different calculus, not shorthand for the Church rules.

Definition 5.19 — Curry-style System F

Curry terms are m,n::=xλx.mmn, modulo alpha-equivalence of term binders. Types, type contexts, and term contexts are those of definition 5.3. The judgment Δ;ΓCm:A has the variable and arrow rules

x:AΓ
Δ;ΓCx:A
C-Var
Δ;Γ,x:ACm:B
Δ;ΓCλx.m:AB
C-Arr-I
Δ;ΓCm:ABΔ;ΓCn:A
Δ;ΓCmn:B
C-Arr-E

and the syntax-invisible universal rules

Δ,X;ΓCm:AXΔ
Δ;ΓCm:X.A
C-All-I
Δ;ΓCm:X.AΔB type
Δ;ΓCm:A[B/X]
C-All-E

All contexts in these rules are required to be well formed.

The raw identity λx.x has type XX under type context X, and then C-All-I gives it type I in the empty type context. The same raw term also has many monomorphic types. A Curry term therefore does not determine where polymorphism was introduced or eliminated.

Definition 5.20 — Erasure

Erasure from Church terms to Curry terms is |x|=x,|λx:A.t|=λx.|t|,|tu|=|t||u|,|ΛX.t|=|t|,|t[A]|=|t|.

Theorem 5.21 — Erasure and decoration

For every well-formed Δ;Γ:

  1. if Δ;Γt:A, then Δ;ΓC|t|:A;

  2. if Δ;ΓCm:A, then there is a Church term t such that |t|=m and Δ;Γt:A.

The decoration in item 2 is attached to a derivation, not determined by the raw term alone.

Proof of Theorem 5.21 — Erasure and decoration

Proof. For item 1, induct on the Church typing derivation. Variable, lambda, and application rules erase to their Curry counterparts. A Church type abstraction erases its constructor and the induction hypothesis is followed by C-All-I. A Church type application likewise erases and is followed by C-All-E with the same type argument.

For item 2, induct on the Curry derivation and construct the decoration. At a variable use the same variable. At arrow introduction, decorate the premise to t and use λx:A.t; at arrow elimination, decorate both premises and apply the resulting terms. At C-All-I, decorate the premise to t and return ΛX.t. At C-All-E, decorate the premise to t and return t[B]. Each construction has erasure m because the two universal constructors erase. These five cases are all the Curry rules. ◻

For the opening expression, the Curry derivation decorates its two occurrences of f differently: the function occurrence becomes f[I] and the argument occurrence remains f. Erasure forgets this choice and returns (λf.ff)(λx.x). Algorithm W cannot reconstruct the choice because it insists that a lambda-bound f have a monotype.

Exercise 5.8

★★☆ Give two Church decorations of the Curry term λx.x with different System F types. Then give two different Church decorations, at the same type II, of a Curry term containing at least one application. Draw the Curry derivations whose universal steps produce the decorations.

Checking and inference are different problems

For Church syntax, every polymorphic choice is written. A checker follows the outer term constructor, recursively computes one type, and compares finite type trees modulo alpha-equivalence.

Proposition 5.22 — Decidable Church checking

There is a terminating algorithm which, given finite Δ,Γ,t, decides whether there is a type A with Δ;Γt:A and, if so, returns that unique type up to alpha-equivalence.

Proof of Proposition 5.22 — Decidable Church checking

Proof. First decide Δ typectx and ΔΓ ctx by their displayed formation rules; reject if either check fails. Then recurse on t. A variable looks up its unique declaration. For λx:A.u, first decide formation of A, recurse on u under x:A after alpha-freshening x away from Γ, and return AB. For t1t2, recurse on both subterms; accept exactly when the first result is an arrow whose domain is alpha-equal to the second result. For ΛX.u, alpha-freshen the displayed binder away from Δ, recurse under X, and return X.A. For u[B], decide formation of B, recurse on u, and accept exactly when its result is X.A, returning A[B/X]. Each call is on a strict subterm; formation and alpha-equality of finite types are decidable by structural recursion. Induction on t proves soundness, and inversion of the five typing rules proves completeness and uniqueness. ◻

The corresponding question for Curry syntax is harder because the input does not say where to insert C-All-I and C-All-E. There are two decision problems:

  • typability: given m, does any Δ,Γ,A yield Δ;ΓCm:A?

  • Curry type checking: given Δ,Γ,m,A, is the displayed judgment derivable?

The second phrase must not be confused with checking a fully annotated Church term.

Theorem 5.23 — Undecidability boundary

Typability and type checking for Curry-style System F are effectively interreducible and undecidable.

Proof of Theorem 5.23 — Undecidability boundary

Proof. This is the one decision-theoretic import in the chapter. Wells proves the result for raw lambda terms, arrows, and universal types. His type-variable context is implicit: from our finite input one forgets Δ, while in the other direction one takes Δ=ftv(Γ,A) after checking scope. These translations are effective. Wells also works with canonical representatives that identify harmless permutations of independent quantifiers and erase a universal quantifier X.A when Xftv(A); such a quantifier is called vacuous. His comparison with ordinary type syntax proves that this canonical presentation does not alter derivability [Wel99]. His TYP and TC problems are, respectively, typability of a raw term and checking a supplied raw-term/type pair. They are therefore effectively equivalent to the two problems displayed above. Their effective equivalence and undecidability are [Wel99]. No consequence for the Church checker is being claimed. ◻

Thus the imported fact has one operational consequence for this chapter: the annotations and explicit type applications of Church syntax support the terminating checker above, while erasing them produces a Curry judgment for which even checking a proposed type is undecidable.

Exercise 5.9

★★☆ Erase the opening term of equation 5.1. Run the constraint generation clauses of Algorithm W in definition 3.28 until the occurs-check equation appears. Then annotate the same raw term by following its Curry derivation and show which occurrence receives the invisible universal elimination. Explain in one sentence why adding a cleverer first-order unifier cannot repair the HM derivation.

Strong normalization

Safety excludes stuck states, but not infinite calculation. Weak normalization merely supplies one path to a normal form and therefore cannot exclude a different divergent path. Strong normalization excludes every infinite beta sequence. We prove that every well-typed term admits no infinite sequence of compatible beta steps, even when reduction is allowed beneath both kinds of abstraction. Write SN provisionally for the System F terms with no infinite compatible beta-reduction sequence. The attempted type-indexed definition next fails at universal types, motivating the candidate-valued definition in definition 5.25.

A first attempt copies the simple-type proof. If reducibility at A were already defined as a set RA, the tempting universal clause would be tRX.AtSN  and  t[C]RA[C/X] for every closed type C. This is not a structural recursive definition. Take A=XX and C=I=Y.YY. Defining RI would require the not-yet-defined set RII, whose index is larger than I, not a proper subexpression of it. In chapter 2, every recursive call was at a proper subexpression of the current type; impredicative instantiation destroys precisely that decrease.

The repair turns the old proof inside out. The three saturation properties proved for simple-type reducibility in lemma 2.40 become the definition of an admissible interpretation. We then quantify over every set satisfying them. Such a set is a reducibility candidate: a candidate for being the interpretation assigned to a type. The arbitrary candidate, not the syntax of a representing type, breaks the circle. The repaired interpretation recurses on the proper syntactic body A of X.A under an extended valuation. It never recurses on the substituted type A[C/X] that caused the failed definition above.

The proof has four stages. First define the admissible candidate sets and prove that the operations needed by arrows and universals preserve them. Second interpret each type as a candidate under a valuation. Third prove the two expansion lemmas that run term and type introduction backwards. Finally induct on typing to obtain reducibility, and hence normalization.

A valuation assigns an arbitrary reducibility candidate and a closed type to each type variable. The interpretation of X.A recurses on the proper body A under every extension of that valuation, never on the larger substitution instance A[C/X].

The proof uses the following operations. Their definitions appear in the order in which the four stages need them. SNstrongly normalizing System F termsSN0members of SN with no free type variablesν(t)reduction height of tSNF(C,R)candidate-valued familyt[A]object-language type applicationA[B/X], t[B/X]single type substitutionA[η^], t[η^]valuation substitutiont[σ]simultaneous term substitution[[A]]ηcandidate interpreting A[t]βbeta-equivalence class, used later in relation lifting

Candidates

Definition 5.24 — Strong normalization and neutral terms

Strong normalization, written tSN, is the property that no infinite sequence t=t0βt1β exists. A neutral term has an outer constructor that is neither λ nor Λ. Thus variables, ordinary applications, and type applications are neutral; a beta redex is neutral because its outer constructor is an application. This is the same deliberately broad notion used in the saturation proof of chapter 2. It is needed for expansion: (CR3) below admits a redex after all its reducts have been controlled. Excluding abstractions matters because placing a lambda or type lambda in an elimination position creates a new root redex not among the abstraction’s own reducts.

Compatible beta reduction is finitely branching because a finite term has only finitely many redex occurrences. First, its restriction to SN is well founded. A term is reduction-minimal in a subset when none of its one-step reducts belongs to that subset. If a nonempty subset of SN had no reduction-minimal member, numerical syntax codes would let us choose, by ordinary recursion, the least-coded reduct that remains in the subset. That would be an infinite reduction sequence. The fixed least-coded choice is definable, so this argument invokes no choice principle.

Well-founded recursion on that restricted relation now defines, for tSN, its reduction height ν(t):={0,t has no one-step reduct,1+max{ν(t)tβt},otherwise. The recursive calls are already defined at the proper reducts, and the maximum is over the finite set of one-step reducts. Thus existence of the maximum is a consequence of well-founded recursion and finite branching, not a premise used to establish either fact.

We also write SN0 for the strongly normalizing terms with no free type variables; free term variables remain permitted. The unrestricted symbol SN continues to include terms with free type variables.

Definition 5.25 — Reducibility candidate

Work with Church terms having no free type variables, but permit free term variables. A reducibility candidate is a set R of such terms satisfying

  1. RSN0;

  2. if tR and tβt, then tR;

  3. if t is neutral and every one-step reduct of t belongs to R, then tR.

No typing judgment occurs in this definition.

Condition (CR3) includes variables: a variable is neutral and has no reducts, so it belongs to every candidate. If a neutral redex has all one-step reducts in R, the same condition puts the redex itself in R. This is beta expansion after all competing reductions have already been controlled. Without the neutrality side condition, every irreducible abstraction would belong to every candidate vacuously, and elimination could then create an uncontrolled root redex.

There is no size ambiguity in “every candidate.” Finite Church terms form a countable meta-level set, so candidates form a subcollection of its power set in the fixed classical ZF metatheory. The quantifier in the universal candidate construction below ranges over that fixed set; it is not a quantifier inside System F. The construction is nevertheless impredicative: the candidate being defined is itself among the candidates over which its membership condition may quantify. This is legitimate set formation by Separation—the axiom saying that a definable subcollection of a fixed set is itself a set—over the already fixed power set of terms, rather than a construction of that power set. No claim that this particular construction is predicative is intended.

The universal candidate construction below accepts a family F(C,R) of a closed formed type and a candidate. Although C does not occur syntactically in its membership test, the type component later closes annotations and type applications in the interpreted term, while R determines which closed terms count as reducible at the quantified variable. Identifying these two jobs would make the interpretation recurse on substituted types and recreate the impredicative circularity above.

Lemma 5.26 — Elementary candidate constructions

The following sets are reducibility candidates.

  1. SN0.

  2. Every intersection iIRi of candidates, with the empty intersection taken to be SN0. Thus arbitrary intersections of candidates are candidates, and SN0 is the largest candidate under inclusion.

  3. If R,S are candidates, then RS:={tSN0for every uR, tuS}.

  4. Let F(C,R) be a candidate for every closed formed type C and candidate R. Then F:={tSN0for every closed C and candidate R, t[C]F(C,R)} is a candidate.

Proof of Lemma 5.26 — Elementary candidate constructions

Proof. For item 1, (CR1) follows from the definition and (CR2) because an infinite sequence from a reduct would extend to one from its predecessor. For (CR3), if a neutral term had an infinite reduction, its first reduct would also admit an infinite reduction, contradicting the assumption that every reduct lies in SN0.

Intersections inherit all three clauses pointwise. We prove the arrow case in detail. Its (CR1) is part of the definition. If t is in RS and tβt, then t is strongly normalizing. For uR, the step tuβtu and (CR2) for S give tuS; hence tRS.

For (CR3), let t be neutral and suppose every reduct of t is in RS. If t had an infinite reduction, its first reduct would contradict (CR1) for RS; hence t is strongly normalizing. Fix uR and induct on its reduction height ν(u). The application tu is neutral. Each of its one-step reducts has one of two forms: tu(tβt),tu(uβu). The first belongs to S because tRS. For the second, (CR2) gives uR and ν(u)<ν(u), so the induction hypothesis applies. There is no root beta step because t is not a lambda. Thus (CR3) for S gives tuS.

For item 4, (CR1) is again built in. If t takes a step, then so does t[C] in its operator; (CR2) of every F(C,R) proves closure. Finally let t be neutral and all its reducts belong to F. It is strongly normalizing by the first-step argument. For fixed C,R, the term t[C] is neutral. Its reducts are precisely t[C] with tβt: no type beta occurs because t is not a type abstraction. Every such reduct belongs to F(C,R), so its (CR3) gives t[C]F(C,R). Hence tF. ◻

Interpreting types

Definition 5.27 — Candidate valuation and type interpretation

A candidate valuation η for Δ assigns to every XΔ a pair (CX,RX) consisting of a closed formed type CX and a reducibility candidate RX. Write η^ for the type substitution XCX.

The candidate [[A]]η is defined by recursion on A: [[X]]η:=RX,[[AB]]η:=[[A]]η[[B]]η,[[X.A]]η:={tSN0 | for every closed C and candidate R,t[C][[A]]η[X(C,R)]}. Bound variables are first freshened away from the finite domain of η. The displayed clauses inspect only RX. The companion CX is carried so that η^ can close the type annotations in the term interpreted by the fundamental theorem.

Lemma 9.28 — Candidate-component independence

Let η and η be candidate valuations. If their candidate components agree at every variable free in A, then [[A]]η=[[A]]η. Their closed-type components may differ.

Proof of Lemma 9.28 — Candidate-component independence

Proof. Induct structurally on A, universally quantifying the valuation domains and both valuations in the induction hypothesis. Variables use the assumed candidate equality, and arrows use the two induction hypotheses. At X.B, extend both valuations by pairs (C,R) having the same candidate component. For every closed C and candidate R, the induction hypothesis gives [[B]]η[X(C,R)]=[[B]]η[X(C,R)]. Intersecting these equal membership conditions proves the claim. ◻

The first component CX tells us what to substitute into the annotations of a term. The second component RX tells us which terms count as reducible at X. Identifying these two jobs would recreate the circularity: the set interpreting a type is not defined merely by inspecting the syntax of the closed type assigned to it. A candidate may therefore be assigned to any closed type, including a universal type syntactically larger than the type whose body is being interpreted. The phrase “assigned to a type” means precisely the pair (CX,RX) in a valuation.

Here is the smallest useful calculation. Let η(X)=(I,R0), where R0 is any candidate. Then [[X]]η=R0,[[XX]]η=R0R0,[[Y.YX]]η={tSN0 | for every closed C and candidate R,t[C]RR0}. The bound Y ranges over a fresh pair (C,R); the free X continues to use the fixed pair (I,R0). This is the distinction that makes the universal clause impredicative without making its definition circular. For a concrete instance, take R0=SN0 and a term variable x:I. Then ΛY.λy:Y.x[[Y.YX]]X(I,SN0). Fix a closed C, a candidate R, and uR. Put qC:=(ΛY.λy:Y.x)[C]. By (CR1), uSN0, so its reduction height ν(u) is defined. The function λy:C.x is beta-normal; hence the immediate reducts of (λy:C.x)u are exactly x and the terms (λy:C.x)u with uβu. Induction on ν(u) puts the latter in SN0, so no infinite reduction can begin at the displayed term. A second induction on ν(u) proves qCuSN0: its immediate reducts are (λy:C.x)u and the terms qCu at smaller height. The term qC itself has the single reduct λy:C.x, hence lies in SN0; this supplies the leading strong-normalization condition in the definition of RSN0. Therefore qCRSN0 for every C,R. The outer type abstraction is beta-normal and type-closed, so the universal candidate clause gives the displayed membership.

Lemma 5.28 — Interpretations are candidates

For every A formed under Δ and every candidate valuation η for Δ, the set [[A]]η is a reducibility candidate.

Proof of Lemma 5.28 — Interpretations are candidates

Proof. Induct on A, universally quantifying Δ and η in the induction hypothesis. A variable is assigned a candidate. An arrow uses item 3 of lemma 5.26. At X.A, the induction hypothesis says that (C,R)[[A]]η[X(C,R)] is a candidate-valued family for every closed C and candidate R. Item 4 of the same lemma is exactly the displayed universal clause. ◻

Lemma 9.30 — Interpretation irrelevance

If candidate valuations η and η agree on every variable in ftv(A), then [[A]]η=[[A]]η.

Proof of Lemma 9.30 — Interpretation irrelevance

Proof. Agreement of valuations implies equality of their candidate components at every free variable of A. Apply lemma 9.28. ◻

Universal elimination instantiates a syntactic type while extending its candidate valuation. For B formed over the domain of η, the required commuting equation is [[A[B/X]]]η=[[A]]η[X(B[η^],[[B]]η)].

Lemma 5.29 — Candidate substitution

Let X be fresh for the domain of η, and let B be formed over that domain. Put Bη:=B[η^],SB:=[[B]]η. Then, for every A whose free variables lie in dom(η){X}, [[A[B/X]]]η=[[A]]η[X(Bη,SB)].

Proof of Lemma 5.29 — Candidate substitution

Proof. Induct on A, universally quantifying η, B, and their well-formed domains in the induction hypothesis. If A=X, both sides are SB. If A=YX, both sides are RY. The arrow case applies the two induction hypotheses to the domain and codomain.

Let A=Y.A0. Choose Y distinct from X and fresh for B,η. Membership of a term t in the left side means that, for every closed C and candidate R, t[C][[A0[B/X]]]η[Y(C,R)]. Apply the induction hypothesis to A0 under the extended valuation. The instance supplied by that hypothesis initially contains the pair (B[η[Y(C,R)]^],[[B]]η[Y(C,R)]). Because Yftv(B), simultaneous type substitution and interpretation irrelevance give B[η[Y(C,R)]^]=B[η^]=Bη,[[B]]η[Y(C,R)]=[[B]]η=SB. After these equalities identify the inserted pair, the two map extensions commute because XY: η[Y(C,R)][X(Bη,SB)]=η[X(Bη,SB)][Y(C,R)]. Thus the displayed membership condition is exactly membership in the right side’s interpretation of Y.A0. The built-in tSN0 condition is identical on both sides. Hence the two sets are equal. ◻

Lemma 5.32 — Reflection through a fresh substitution

The following two assertions hold.

  1. If yfv(s) and s[y/x]SN, then sSN.

  2. If C is a closed formed type and s[C/X]SN, then sSN.

Proof of Lemma 5.32 — Reflection through a fresh substitution

Proof. Each displayed substitution carries every compatible beta step sβs to a compatible beta step between the substituted terms. Constructor steps follow directly. A term-beta root has the form (λz:A.r)u. Alpha-rename its binder so that z{x,y}fv(u). Then ((λz:A.r)u)[y/x]ββr[y/x][u[y/x]/z]=compositionr[u/z][y/x]. At a type-beta root under the term substitution, the term and type substitutions commute: ((ΛY.r)[B])[y/x]ββr[y/x][B/Y]=commutationr[B/Y][y/x]. For substitution by [C/X], the term-beta root uses the mixed composition equation in equation 5.2. At a type-beta root, alpha-rename its binder so that YX and Yftv(C)ftv(B), and calculate ((ΛY.r)[B])[C/X]ββr[C/X][B[C/X]/Y]=compositionr[B/Y][C/X]. Thus an infinite reduction from s would be carried step for step to an infinite reduction from s[y/x] or s[C/X]. Either hypothesis excludes that possibility. ◻

Expansion through abstractions

Candidate closure is directed from a redex to its reduct. Introduction rules require the reverse move: from reducibility of every substituted body to reducibility of the abstraction. Lemma 5.30, Lemma 5.31 prove that expansion principle for term and type abstraction, respectively.

Lemma 5.30 — Term-abstraction expansion

Let R,S be candidates, let A be a closed formed type, and let s have no free type variables. If s[u/x]S for every uR, then λx:A.sRS.

Proof of Lemma 5.30 — Term-abstraction expansion

Proof. Choose a term variable yfv(s). It is neutral and normal, so (CR3) gives yR. The hypothesis gives s[y/x]S, hence s[y/x]SN by (CR1). Item 1 of lemma 5.32 gives sSN; the hypothesis that s has no free type variables then gives sSN0. The abstraction is strongly normalizing because all its reductions occur in s.

We prove simultaneously, for every strongly normalizing type-closed body s satisfying the displayed hypothesis and every uR, that (λx:A.s)uS. Induct on the lexicographic pair (ν(s),ν(u)): first compare the left components and compare the right components only when the left ones are equal. The required induction is ordinary induction on ν(s), nested with ordinary induction on ν(u) at a fixed first component. The redex is neutral, so use (CR3) for S. Its one-step reducts are:

  1. the root reduct s[u/x], which belongs to S by the displayed hypothesis;

  2. (λx:A.s)u for sβs;

  3. (λx:A.s)u for uβu.

In the second case, s is strongly normalizing and, for every wR, s[w/x]βs[w/x]; the displayed hypothesis and (CR2) give s[w/x]S. The outer induction hypothesis applies. In the third case, (CR2) gives uR and the inner measure decreases. Therefore every reduct lies in S, and (CR3) completes the proof. ◻

The quantifiers in item 2 below are essential: the same substituted body s[C/X] must lie in every candidate value F(C,R) supplied at C; it is not enough to choose one convenient candidate for each type.

Lemma 5.31 — Type-abstraction expansion

Let F(C,R) be a candidate-valued family. Suppose s may contain the free type variable X but no other free type variable. If, for every closed type C and candidate R, one has s[C/X]F(C,R), then ΛX.sF.

Proof of Lemma 5.31 — Type-abstraction expansion

Proof. Choose the closed type I and candidate SN0. The hypothesis and (CR1) give s[I/X]SN, so item 2 of lemma 5.32 gives sSN. The type abstraction is strongly normalizing and has no free type variables: its body is strongly normalizing, and ΛX binds its only possible free type variable. Fix C,R. Prove (ΛX.s)[C]F(C,R) by induction on ν(s) and use (CR3). The root reduct s[C/X] belongs by hypothesis. Every other reduct is (ΛX.s)[C] with sβs. Then s[D/X] is a reduct of s[D/X] for every closed D; (CR2) preserves all the hypotheses for s, whose reduction height is smaller. The induction hypothesis puts each competing reduct in F(C,R). Hence (CR3) gives the required membership. ◻

In the proof of theorem 5.34, replacing a free term or type variable by a fresh closed witness first proves normalization of the substituted term. In particular, normalization of s[C/X] for one closed C gives normalization of s by item 2 of lemma 5.32; the type-abstraction case uses exactly this step.

The fundamental theorem

Definition 5.33 — Reducible term substitution

Let η be a candidate valuation for Δ. A term substitution σ is η-reducible for Γ=x1:A1,,xn:An when it sends each xi to a term with no free type variables and σ(xi)[[Ai]]η. Variables outside Γ are fixed. Write t[η^][σ] for first substituting the closed types in all annotations and type arguments and then substituting the terms.

Theorem 5.34 — Fundamental theorem of reducibility

If Δ;Γt:A, η is a candidate valuation for Δ, and σ is η-reducible for Γ, then t[η^][σ][[A]]η.

Proof of Theorem 5.34 — Fundamental theorem of reducibility

Proof. Induct on the typing derivation, organized by its final rule.

For F-Var, the transformed term is σ(x), which belongs to the required candidate by definition of reducible substitution.

For F-Arr-E, the induction hypotheses give t[η^][σ][[A]]η[[B]]η,u[η^][σ][[A]]η. The definition of the arrow candidate puts their application in [[B]]η.

For F-Arr-I, choose the binder x away from every free variable occurring in the finite family {σ(y)ydom(Γ)}. Put s=t[η^][σ], leaving x free. We verify the two hypotheses of term-abstraction expansion. The type A[η^] is closed. Moreover s has no free type variables: scope bounds the free type variables of t by Δ, η^ replaces all of them by closed types, and every image of σ is type-closed.

Every candidate contains a variable y chosen fresh for s and all substitution images. Extend σ by xy; the induction hypothesis and the term/term composition equation in equation 5.2 give t[η^][σ,xy]=s[y/x][[B]]η. Thus s[y/x] is strongly normalizing, and lemma 5.32 gives sSN. For every u[[A]]η, extend σ by xu. The same term/term equation and the induction hypothesis give s[u/x][[B]]η. Term-abstraction expansion yields λx:A[η^].s[[A]]η[[B]]η. This lambda is exactly the transformed conclusion term.

For F-All-E, the induction hypothesis gives t[η^][σ][[X.A]]η. Use the universal clause with the closed type C=B[η^] and candidate R=[[B]]η. It gives the transformed type application in [[A]]η[X(C,R)]. Candidate substitution gives [[A]]η[X(C,R)]=[[A[B/X]]]η, the interpretation of the conclusion type.

Finally consider F-All-I. Put s=t[η^][σ], leaving X free, and write η:=η[X(C,R)] for arbitrary closed C and candidate R.

Since Xftv(Γ), every declaration x:B in Γ satisfies Xftv(B). Interpretation irrelevance gives [[B]]η=[[B]]η for each such declaration. Thus the same σ is also η-reducible for Γ, and the induction hypothesis under η gives t[η^][σ][[A]]η. Every closed-type component of η is type-closed, so η^ is η^ followed by the single substitution [C/X]. Because the images of σ have no free type variables, the type substitution does not alter those images. The term–type composition equation in equation 5.2 therefore gives t[η^][σ]=αs[C/X]. Choose C=I, where I=Y.YY as in equation 5.1, and choose R=SN0. The displayed membership and (CR1) give s[I/X]SN, so lemma 5.32 gives sSN. Type-abstraction expansion, with the displayed family of body candidates, yields ΛX.s[[X.A]]η. This is the transformed conclusion. The induction is complete. ◻

Theorem 5.35 — Strong normalization

If Δ;Γt:A, then tSN. In particular, every closed well-typed term reaches a beta-normal form, and call-by-value evaluation terminates.

Proof of Theorem 5.35 — Strong normalization

Proof. Assign every XΔ the closed type I and the candidate SN0. For each x:A in Γ, use the same term variable x as its substitution image. Every candidate contains every variable by (CR3), so this is a reducible substitution. The fundamental theorem gives t[η^][[A]]η, hence t[η^]SN by (CR1). If t admitted an infinite compatible reduction, apply the second clause of lemma 5.32 successively to the finite family of closed type images in η^. Each application is licensed because the image is a closed formed type, and the step-preservation calculation in that lemma carries the infinite reduction through the substitution. The result would be an infinite reduction of t[η^]. Therefore t is strongly normalizing. A maximal reduction ends in a normal form, and the call-by-value relation is a subrelation. ◻

A neutral spine hS consists of a head term variable h followed by a finite, possibly empty, sequence of term arguments and type arguments in their original order. This notation records mixed applications without placing every term argument before every type argument.

Lemma 9.38 — Normal and neutral shapes

If Δ;Γn:A and n is beta-normal, then n is a term abstraction, a type abstraction, or a neutral term generated from a free term variable by term and type applications. Hence a closed well-typed beta-normal term is an abstraction. If Δ;Γn:X for a type variable X and n is normal, then n is neutral and its head variable is declared in Γ.

Proof of Lemma 9.38 — Normal and neutral shapes

Proof. Induct on the typing derivation, using inversion and normality in the two elimination cases. A variable is neutral. Lambdas and type abstractions are the two introduction cases. If n=tu, inversion types t at an arrow and u at its domain. Normality excludes a term-abstraction operator, and typing inversion excludes a type abstraction because its type has universal, not arrow, head. The induction hypothesis gives t=hS for a head variable h; appending the normal u preserves h. For n=t[B], inversion types t at a universal type. Normality excludes a type-abstraction operator, while typing inversion excludes a term abstraction; the induction hypothesis again gives a neutral t with the same head variable. These cases exhaust the typing rules.

For the typed conclusion at X, inversion excludes both abstractions: their conclusion types have arrow and universal heads. The remaining neutral’s head is a free term variable, and the variable rule places it in Γ. With empty Γ, no such neutral exists. ◻

Corollary 5.36 — Syntactic consistency

In classical ZF, the pure Church-style System F of definition 5.1, definition 5.4 has no closed term of type X.X.

Proof of Corollary 5.36 — Syntactic consistency

Proof. Suppose ;t:X.X. Normalize t and use subject reduction. Its normal form must be ΛX.u, with X;u:X: by lemma 9.38, a closed normal term cannot be neutral and the universal conclusion excludes a term lambda. The same lemma gives u=hS with h declared in the empty term context. This contradiction proves the claim. ◻

Exercise 5.10

★☆☆ Let VoidF:=X.X. Construct an eliminator abortA:VoidFA for every formed A. Explain why this construction does not contradict corollary 5.36.

Exercise 5.11

★★★

  1. Prove directly that every candidate contains every neutral normal form with no free type variables, not only variables.

  2. In the arrow-candidate proof, remove the explicit requirement tSN0 from the definition. Choose a fresh variable zR, derive tSN from tzS using lemma 5.32, and then recheck (CR2) and (CR3) with this derived fact in place of the deleted conjunct.

  3. Reprove (CR3) for the universal candidate construction when the neutral term is itself a type application q[D]. List every immediate reduct of (q[D])[C] and explain why no new root type-beta redex appears.

The eta boundary of the encodings

To prove that two distinct normal forms are not beta-convertible, we need one final property of reduction. Strong normalization alone is insufficient: a terminating relation may still lead to two different normal forms. Compatible beta reduction is confluent.

Trying to prove a diamond directly for one compatible beta step fails when substitution duplicates a redex. Put r=(λy.y)z. Then (λx.fxx)r reduces in one step either to frr or to (λx.fxx)z. The latter reaches fzz in one step, whereas the former needs one contraction in each copy of r. The reducts therefore need not rejoin in one ordinary step. Parallel reduction repairs this by contracting any finite family of redexes, including both copies, at once.

Definition 9.40 — Parallel beta reduction

Parallel reduction β contracts any finite collection of redexes in one step, including nested redexes. It is generated by the following seven rules; this is the complete definition.

xβx
P-Var
sβs
λx:A.sβλx:A.s
P-Lam
sβsuβu
suβsu
P-App
sβs
ΛX.sβΛX.s
P-TLam
sβs
s[A]βs[A]
P-TApp
sβsuβu
(λx:A.s)uβs[u/x]
P-Beta
sβs
(ΛX.s)[A]βs[A/X]
P-TBeta

Structural induction gives tβt for every term t. The type annotations and type arguments contain no type-level redexes in System F, so the rules leave them fixed except when P-TBeta substitutes an argument.

Lemma 5.37 — Parallel substitution

The two substitution laws are sβs, uβus[u/x]βs[u/x],sβss[A/X]βs[A/X].

Proof of Lemma 5.37 — Parallel substitution

Proof. Prove the term-substitution assertion by induction on the derivation sβs. A distinguished variable uses uβu; another variable is reflexive. Constructor clauses apply their induction hypotheses after freshening binders away from u,u. In the term-beta root case, alpha-freshen the contracted binder y so that yx and yfv(u)fv(u). Then use the two induction hypotheses and the composition equation s0[v/y][u/x]=s0[u/x][v[u/x]/y] from equation 5.2; this is precisely the term obtained by substituting into the contracted parallel reduct. The type-beta root is structural for term substitution.

The type-substitution assertion is the same induction. Its type-beta root first alpha-freshens the contracted binder Y so that YX and Yftv(A), and then uses the type-substitution composition equality in equation 5.2. The term-beta root uses the term–type commutation equation there after the term binder has been freshened. Thus both the term-beta and type-beta roots commute with type substitution. ◻

Lemma 9.42 — Parallel diamond

If tβu and tβv, then some w satisfies uβw and vβw.

Proof of Lemma 9.42 — Parallel diamond

Proof. Use simultaneous induction on two parallel derivations with a common source. The possible last-rule pairs are determined by the source’s outer constructor: source shapepossible pair, up to exchangexPVar/PVarλx:A.sPLam/PLamΛX.sPTLam/PTLamsu with non-lambda headPApp/PApps[A] with non-type-lambda headPTApp/PTApp(λx:A.s)uPBeta/PBeta,PBeta/PApp,PApp/PApp(ΛX.s)[A]PTBeta/PTBeta,PTBeta/PTApp,PTApp/PTApp For every constructor/constructor pair, apply the induction hypothesis to each immediate subterm. A parallel step either preserves the outer constructor or contracts one of the two beta-redex shapes; those shapes have different eliminators.

It remains to treat pairs in which at least one derivation contracts the root. For a term-beta source (λx:A.s)u, suppose one derivation contracts the root to s1[u1/x] while the other preserves application and reaches (λx:A.s2)u2. Inverting the preserving derivation’s left premise λx:A.sβλx:A.s2 forces its last rule to be P-Lam, and therefore supplies the body derivation sβs2 needed by the induction hypothesis. The induction hypotheses give common parallel reducts s of s1,s2 and u of u1,u2. Parallel substitution gives s1[u1/x]βs[u/x], while the root clause gives (λx:A.s2)u2βs[u/x]. If both derivations contract the root, the same substitution calculation joins them. For a type-beta source (ΛX.s)[A], the body induction hypotheses give reducts with a common successor s, parallel type substitution sends the contracted branch to s[A/X], and P-TBeta sends the constructor branch there. Hence the parallel relation has the diamond property. ◻

Lemma 9.43 — Sequentializing parallel reduction

Every ordinary beta step is a parallel step. If tβt, then tβt.

Proof of Lemma 9.43 — Sequentializing parallel reduction

Proof. Every one-step beta contraction is a parallel step. Conversely, induction on a derivation tβt gives tβt. The variable case is empty. Each of P-Lam, P-App, P-TLam, and P-TApp uses the induction hypotheses under its compatible contexts. In the P-Beta case they give (λx:A.s)uβ(λx:A.s)uβs[u/x]. The P-TBeta root instead ends (ΛX.s)[A]βs[A/X]. Thus parallel steps can be sequentialized. ◻

Theorem 5.38 — Church–Rosser

Compatible beta reduction is confluent: if tβu and tβv, then there is w with uβw and vβw. Hence a term has at most one beta-normal form up to alpha-equivalence.

Proof of Theorem 5.38 — Church–Rosser

Proof. The diamond property of lemma 9.42 extends from one parallel step to its reflexive transitive closure by tiling. In the following diagrams every solid arrow is one β step. A row or column denotes the composite β path. The left square is one diamond. Repeating that square along the upper path gives the strip on the right; adjoining one strip for each step of the other path tiles a rectangle. Mathematical diagramDiagram The represented invariant is that the two paths around every square have a common endpoint. First prove the strip property: if aβb and aβc, then some d satisfies bβd and cβd. Induct on the second path. Its empty case takes d=b. In its successor case aβc1βc, the diamond for the two first steps produces e with bβe and c1βe; the induction hypothesis applied to c1βe and c1βc completes the strip. Now induct on the first path in a peak bβaβc, using one strip for its first step. This tiles the whole rectangle and gives a common parallel reduct.

Ordinary beta paths embed into parallel paths, and parallel paths sequentialize back to ordinary beta paths; hence compatible beta reduction is confluent. Two normal forms with a common reduct must themselves be alpha-equal, which proves uniqueness. ◻

Corollary 9.45 — Conversion has a common reduct

If u=βv, then some w satisfies uβw and vβw.

Proof of Corollary 9.45 — Conversion has a common reduct

Proof. Induct on the construction of u=βv. Reflexivity and a single forward or backward step are immediate; symmetry exchanges the two legs. For transitivity, suppose uβpβv and vβqβw. Confluence joins the two reductions from v at some r: pβrβq. Appending the outer legs gives uβrβw, as required. ◻

Proposition 5.39 — Closed normal booleans and naturals

Up to alpha-equivalence:

  1. The only closed beta-normal inhabitants of the boolean encoding are trueF and falseF.

  2. The closed beta-normal inhabitants of the natural-number encoding are exactly ΛX.λz:X.λs:XX.snz, for n0.

Consequently every closed term at either type is beta-convertible to one of the displayed canonical forms.

Proof of Proposition 5.39 — Closed normal booleans and naturals

Proof. Invert the typing of a closed normal term. At either universal type it must begin with ΛX by lemma 9.38. Repeating inversion at the arrow types produces the displayed term lambdas.

For booleans, the remaining body has type X under t:X,f:X. A neutral normal form of atomic type must be headed by a variable, and neither variable is a function. Hence the body is t or f.

For naturals, the remaining context is z:X,s:XX. A neutral normal form of type X is either z or su. Apply the head-form argument recursively to u:X: the only arrow-typed variable in scope is s, so no other application head is possible. Since the term is finite, it is snz for a unique n. For every closed typed term t, strong normalization gives tβn with n normal, subject reduction preserves its type, and Church–Rosser gives uniqueness of n up to alpha-equivalence. ◻

We can now state the exact boundary of the encodings. Let p:A×FB be a variable. Both pandfstF(p),sndF(p)F are beta-normal after the abbreviations are expanded, and they are not alpha-equal: the second begins with a type abstraction, while the first is neutral. By Church–Rosser they are not beta-convertible. Thus the product encoding has both projection beta laws, but not product eta as a beta law.

The corresponding sum boundary is visible without inventing an eta law. For variables s:A+FB,f:AC,g:BC,q:CD, the two normal terms q(s[C]fg)ands[D](λa:A.q(fa))(λb:B.q(gb)) are distinct. A primitive sum calculus may choose a commuting conversion equating them; the Church encoding under beta conversion does not. These facts do not diminish the constructor calculations already proved. They say exactly which equations those calculations establish.

Why the full-function set interpretation fails

The reducibility interpretation was designed to prove termination, not to assign an ordinary mathematical value to every term. It is natural to ask for a classical set interpretation that extends the familiar model of simple types: interpret AB by the full set of all functions and find some set interpreting X.A. Impredicativity obstructs this request.

Double brackets always denote an interpretation; their subscript identifies which one. Thus [[A]]η above is a reducibility candidate, whereas [[A]]set below would be a set in the assumed classical model.

Definition 9.47 — Full-function interpretation package

A full-function interpretation package for Church-style impredicative System F in classical set theory consists of interpretations satisfying all of the following clauses:

  1. type variables range over arbitrary sets and every type denotes a set; the denotation of a type depends only on its free type variables and is unchanged by irrelevant extensions of the type environment;

  2. every typed term denotes an element of its interpreted type as a function of type and term environments; this denotation depends only on the free variables of the judgment and is unchanged by irrelevant environment extensions;

  3. AB denotes the full set of all functions from [[A]]set to [[B]]set;

  4. term variables, abstraction, and application have their ordinary set meanings;

  5. term substitution and term beta are sound, type application respects equal denotations, and type beta is sound.

No particular set-theoretic intersection formula for is assumed.

Definition 9.48 — T-algebras and splitting

Fix a set B and define T(X):=(XB)B,T(h)(ϕ)(k):=ϕ(kh) for h:XY, ϕ:T(X), and k:YB. A T-algebra is a pair (X,α) with α:T(X)X. A T-algebra homomorphism h:(X,α)(Y,β) is a function h:XY satisfying hα=βT(h). The algebra is weakly initial when it has at least one homomorphism to every T-algebra, and initial when it has exactly one. An endomap e:PP is idempotent when ee=e. A splitting of e consists of a set P and maps r:PP, i:PP such that ir=e and ri=idP.

Lemma 9.49 — Functor laws for T

The action in definition 9.48 satisfies T(id)=id and T(gh)=T(g)T(h). Hence T is a covariant endofunctor on sets.

Proof of Lemma 9.49 — Functor laws for T

Proof. For ϕ:(XB)B and k:XB, T(id)(ϕ)(k)=ϕ(kid)=ϕ(k). For h:XY, g:YZ, and k:ZB, T(gh)(ϕ)(k)=ϕ(kgh)=T(h)(ϕ)(kg)=T(g)(T(h)(ϕ))(k). Since k was arbitrary, T(gh)(ϕ)=T(g)(T(h)(ϕ)); since ϕ was arbitrary, T(gh)=T(g)T(h). The first calculation, with idX in place of gh, gives T(idX)=idT(X). ◻

Theorem 9.50 — Imported stable-restriction interface

Let a full-function interpretation package be given. Put B=[[BoolF]]set. The functor T built from B in definition 9.48 has an initial algebra (P,H).

Proof of Theorem 9.50 — Imported stable-restriction interface

Proof. Put B:=BoolF. For a type variable S, put W(S):=(((SB)B)S)S,P:=S.W(S). Reynolds gives an explicit System F term H:((PB)B)P. The ordinary variable, abstraction, and application clauses interpret it as a structure map H:T(P)P, where P=[[P]]set and T(X)=(XB)B. For an arbitrary algebra f:T(X)X, interpreting p[X]f defines ρf:PX. Term substitution and both beta laws calculate ρfH=fT(ρf), so this algebra is weakly initial. For pP, call p stable when every T-algebra homomorphism α:(X,f)(Y,g) satisfies α(ρf(p))=ρg(p). Let PP be the set of stable elements. Reynolds proves that H restricts to a map H:T(P)P and supplies, for each algebra (X,f), a homomorphism ρf:PX. Put e:=ρH:PP. The factorization clause of Reynolds’s Lemma 3, applied to e, gives ee=e. Hence e is an idempotent endomap of P. Splitting e in the sense of definition 9.48 produces a carrier P on which the induced map H:T(P)P has exactly one homomorphism into every T-algebra. Reynolds’s Lemmas 1–4 supply the explicit terms, the restriction to P, the factorization clause, and the splitting [Rey84]. ◻

Lemma 9.51

The cardinal |X| records the size of a set X up to bijection: |X|=|Y| means that a bijection XY exists. Put 2:={0,1}. Write 2X for the set of functions X2, and define the cardinal exponent by 2|X|:=|2X|. A bijection b:XY induces a bijection ggb1 from 2X to 2Y, so this exponent depends only on the cardinal |X|. For every set X, |X|<2|X|. Here |X|<|Y| means that an injection XY exists but no injection YX exists.

Proof of Lemma 9.51

Proof. The map sending xX to the characteristic function of the singleton {x} is injective. It remains to exclude an injection in the other direction.

Suppose i:2XX were injective. Define r:X2X by r(i(g))=g,r(x)=the constant-zero function when xim(i). Injectivity of i makes the first clause unambiguous, and every g2X equals r(i(g)); hence r is surjective. Define d2X by d(x)=1r(x)(x). Surjectivity gives an aX with r(a)=d, whence d(a)=1d(a), a contradiction. Thus no injection 2XX exists. ◻

Theorem 5.40 — Reynolds' set-theoretic obstruction

Impredicative Church-style System F admits no full-function interpretation package in classical set theory.

Proof of Theorem 5.40 — Reynolds' set-theoretic obstruction

Proof. Assume such a package. The denotations of trueF and falseF are distinct: instantiate both at a two-element set and use the full-function arrow clause together with the variable, abstraction, type-application, and type-beta clauses. Choose their distinct denotations b0,b1B, where B=[[BoolF]]set.

By theorem 9.50, T has an initial algebra (X,α). Its structure map is an isomorphism. Let h:(X,α)(T(X),T(α)) be the unique homomorphism. Both αh and idX are endomorphisms of the initial algebra, so they are equal. The homomorphism equation for h then gives hα=T(α)T(h)=T(αh)=idT(X). Hence α:T(X)X is a bijection.

It remains to compare cardinalities without assuming that B has exactly two elements. Map 0 to b0 and 1 to b1 to obtain an injection j:2B. Postcomposition with j gives an injection jX:2XBX. Every function F:2X2 determines a function F:BXB by F(g):={j(F(f)),g=jf for the necessarily unique f:X2,b0,g is not in the image of jX. Restriction along jX recovers jF, so the assignment FF is injective. Its domain is the function set 22X, whose cardinal is 2|2X|=22|X|. Consequently |T(X)|=|BBX|22|X|. Let i:22XT(X) be the injection just constructed, and let s:X2X send x to the characteristic function of {x}. Composing i with the bijection α:T(X)X and then with s gives an injection 22X2X. The Cantor diagonal lemma at the set 2X forbids this injection. The imported interface supplies only the initial algebra; the cardinal comparison and the contradiction are local [Rey84]. ◻

This is not a contradiction in System F. Syntactic consistency was proved in corollary 5.36. Nor does the theorem say that System F has no semantics constructed within set theory. A semantic package avoids clause 3 of definition 9.47 when it assigns to some pair of interpreted sets U,V a proper subset of VU. Such subsets must still contain the denotation of every typed abstraction, and clause 4 must interpret tu by evaluating the element denoted by t at the element denoted by u. The obstruction tells us which naive extension of the simple set model fails, not that impredicative syntax is meaningless.

The remaining question: uniformity

Normalization can classify the inhabitants of one chosen closed type. Repeating that calculation separately at every polymorphic type supplies no induction clause for an arrow or a universal type. We first see this limit at the iterator type H:=X.(XX)XX.

Lemma 5.41 — Normal iterators

Every closed term of H:=X.(XX)XX is beta-convertible to exactly one term in the following list: ΛX.λf:XX.f,ΛX.λf:XX.λx:X.fnx(n0).

Proof of Lemma 5.41 — Normal iterators

Proof. Normalize and invert typing. Write the forced initial abstractions as ΛX.λf:XX.r. The residual term r has type XX under f:XX. If r is neutral, it must be the variable f: applying f even once would produce atomic type X. Otherwise it is λx:X.u, where u:X is normal under f:XX,x:X. The neutral-head argument from proposition 5.39 gives u=fnx for a unique n. Church–Rosser gives uniqueness of the resulting member of the list. ◻

The proof inspects the particular normal forms of H; it does not extend by induction on an arbitrary type. To obtain arrow and universal clauses, relate inputs at two types and lift that relation through each type constructor.

Definition 5.42 — Lifting a relation through an arrow

Let A,B,C,D be closed types. A relation R:AB is a relation between beta-equivalence classes of closed terms of types A and B. If also S:CD, define [f]β (RS) [g]βfor every [a]βR[b]β, one has [fa]βS[gb]β, where f:AC and g:BD are closed. Working with beta-equivalence classes makes the definition independent of the chosen representatives.

The arrow RS here deliberately has the same shape as the candidate arrow in lemma 5.26: both say that related or admitted inputs are sent to related or admitted outputs. It is unrelated to parallel reduction, which is written β.

Put H:=X.(XX)XX, and let ;h:H be closed. Let also f:AA, g:BB, a:A, and b:B be closed.

Proposition 5.43 — Relational uniformity of iterators

For every relation R:AB, [f]β (RR) [g]β,[a]βR[b]β[h[A]fa]β R [h[B]gb]β.

Proof of Proposition 5.43 — Relational uniformity of iterators

Proof. Use lemma 5.41. If the normal form is ΛX.λf.f, the two terms in the conclusion reduce to fa and gb; the arrow-relation hypothesis relates their classes. Otherwise the normal form is the long iterator for some n. Since R is a relation on beta-equivalence classes, it suffices to prove [fna]βR[gnb]β. Induct on n. The zero case is [a]βR[b]β; the successor case applies [f]β(RR)[g]β to the induction hypothesis. ◻

Every term in the proposition is typed, and R was arbitrary. For a closed k:AB, define its graph on beta-equivalence classes of closed a:A and closed b:B by [a]β Rk [b]β[ka]β=[b]β. The definition of Rk is independent of the chosen representatives because application respects beta conversion. The equation k(fa)=βg(ka) for every closed a:A says precisely that [f]β(RkRk)[g]β. The proposition then gives k(h[A]fa)=βh[B]g(ka). In words, transporting an input by k before iterating gives the same result as iterating first and transporting afterward; the square formed by f, g, and k commutes.

This proof is ad hoc: it classifies the normal forms of H, handles the eta-short form directly, and then inducts on the exponent of every long form. The strong-normalization theorem by itself does not state equation 5.5, and repeating a new normal-form classification at every polymorphic type is not a method. A relational semantics must interpret every type as a binary relation and show, by induction on typing, that every polymorphic term preserves the relation assigned to each type variable.

Suggested first pass.

Work in order: calculate the encoding boundary (exercise 5.13), reconstruct normal forms (exercise 5.12), rebuild universal normalization (exercise 9.14), isolate the semantic hypothesis (exercise 5.14), and synthesize the checker (exercise 9.15). No problem is a premise of a later one.

Exercise 5.13

★★☆ Expand the product eta candidate and show that its sides are distinct beta-normal forms. Repeat the calculation for bandΛX.λt:X.λf:X.b[X]tf at neutral b:BoolF; in each case, name the absent primitive uniqueness rule.

Exercise 5.12 — *

★★★ At the parenthesized type X.(XX)(XX) reconstruct lemma 5.41: list the beta-normal inhabitants, including the eta-short shape; prove exhaustiveness; and state the function-eta equation that would identify two of the listed members.

Exercise 9.14

★★★ Let Δ,X;Γt:A be an F-All-I premise, so Xftv(Γ). For a candidate valuation η of Δ and an η-reducible σ for Γ, put s=t[η^][σ] with X free. For arbitrary closed C and candidate R, reconstruct the extended valuation, reducibility of σ, the body equation, one normalizing choice of (C,R), and the conclusion ΛX.s in the universal candidate.

Exercise 5.14 — *

★★☆ Keep clauses 1, 2, 4, and 5 of definition 9.47. Replace clause 3 by F(U,V)VU for each interpreted U,V, where F(U,V) is the set interpreting UV; clause 3 currently sets it equal to VU. Require strict inclusion for at least one pair while retaining denotations of abstractions and application. Identify the abandoned hypothesis of theorem 5.40 and state the exact effect on preservation, normalization, and consistency.

Exercise 9.15

★★★ Practical project.system-f-checker Build an evidence-producing checker in five stages.

  1. Represent the exact five-constructor grammar, with separate scopes for term and type variables. Use de Bruijn indices—natural numbers that name a binder by the number of intervening binders—for type variables, and let d be the number of type binders in scope: a type is formed at depth d when each free type-variable index is less than d. Implement formation tests for types and contexts.

  2. Implement both capture-avoiding substitutions. Test each with a replacement whose free variable would be captured by a naive recursive traversal.

  3. Make infer return a type A and evidence e, and replay e without calling infer. Maintain this invariant: when (d,Γ,t) has every context type formed at depth d, a returned (A,e) has A formed at depth d and e replays independently.

  4. Enumerate compatible beta reducts beneath every term constructor. Recheck every immediate reduct and replay its evidence.

  5. Run a named, decidable suite containing the polymorphic identity and its II instance; rejection of external unannotated self-application, an ill-formed type, and an ill-formed term context; distinct beta-normal short and long product-eta candidates at one type; and the reduct checks from the previous stage. Print one pass/fail line for each case and fail the aggregate when any line fails.

Search the book

Type to search the local edition.