Lectures onType Theory
Chapter 94
Chapter 94Optional

Subject-Dependent Self Types

Prerequisites. Direct starred prerequisites: Chapter 37. No later core chapter depends on this route.

Dependent intersection can add a view B(t) to a subject t whose left-hand type is already known. It cannot define one type T whose membership condition says, for every t:T, that a predicate holds of t itself. The Church encoding of naturals exposes the missing dependency. Its iterator provides n:C:U0.(CC)CC, but induction needs a motive C:NatU0 and the conclusion C(n), where the subject n occurs in its own assigned type.

System S

Convention 94.1 — The frozen System S

System S is Fu and Stump’s Curry-style extension of the Calculus of Constructions. Its terms are untyped lambda terms with globally defined closed constants. Its types add implicit products x:A.B, type-level term abstraction and application, and the subject-dependent self type ιx.T. A global closure may contain a singly recursive type definition XT, but every occurrence of X in T is positive or lies in an erased position. Term definitions are nonrecursive and closed. The metatheorems below apply to this exact signature, not to an unrestricted recursive type equation.

An implicit product classifies a term without adding a lambda. Its binder is erased both at introduction and elimination. The rules are

ΓA typeΓ,x:AB type
Γx:A.B type
S–F
Γ,x:At:BxFV(t)
Γt:x:A.B
S–I
Γt:x:A.BΓu:A
Γt:B[u/x]
S–E
Γ,x:At:BxFV(t)
erase(t)=erase(t)
S–β

The last rule records the computation: implicit abstraction and instantiation perform type substitution but no term reduction.

Definition 94.2 — Subject-dependent self

The type ιx.T binds the term variable x in T. Formation, generation, instantiation, and their erasure equation are

Γ,x:ιx.TT type
Γιx.T type
S-Self-F
Γt:T[t/x]Γιx.T type
Γt:ιx.T
S-Self-Gen
Γt:ιx.T
Γt:T[t/x]
S-Self-Inst
Γt:ιx.T
erase(selfGen(t))=erase(t)=erase(selfInst(t))
S-Self-Erase

The terms in the source conclusions are all the same Curry term t; selfGen and selfInst above name typing steps, not runtime constructors. The rules are inverse changes of type annotation, not a judgmental equation ιx.TT[t/x] valid for arbitrary t.

Let z:ιx.T be neutral. Rule S-Self-Inst changes its type to T[z/x], but no reduction occurs. This is the stuck case: the self rule reveals a dependent view of z without revealing the head constructor of z.

Exercise 94.1

★☆☆ Starting from t:T[t/x], apply S-Self-Gen and then S-Self-Inst. Write the type after each step and compute the erasure. Explain why the calculation does not prove ιx.TT[u/x] for an unrelated u.

The closure restriction does work

The tempting recursive equation Bad:=BadN places Bad to the left of an arrow. If it were admitted equi-recursively, the untyped self-application δ:=λx.xx could receive type BadN and δδ would reproduce itself. This would contradict strong normalization.

Definition 94.3 — Positive recursive closure

For the strong-normalization theorem, a closure entry XT satisfies Pos(X,T) when every non-erased occurrence of X is positive. The polarity calculation is polp(AB)=pol¬p(A)polp(B), and products preserve polarity in their bodies. Occurrences in kinds and in the domain annotation of an implicit product are erased by the target translation and impose no recursive target equation. Mutual recursive type definitions and open recursive right-hand sides are excluded from the frozen closure.

For BadBadN, the occurrence is negative and the closure is rejected. For the Church natural closure below, the recursive occurrences in motive annotations and implicit domains are erased, while the remaining target equation is positive.

Induction from self instantiation

Define a closed recursive type closure μN by Natιx.C:NatU0.(n:Nat.C(n)C(S(n)))C(0)C(x),0λs.λz.z,Sλn.λs.λz.s(nsz). The binders over C and n are implicit. Their erasure gives the ordinary Church type (CC)CC.

Lemma 94.4 — Constructor typing

Under μN, 0:Nat,S:NatNat.

Proof of Lemma 94.4 — Constructor typing

Proof. For zero, fix C, a step s, and a base z:C(0). The term λs.λz.z has the instantiated body type ending in C(λs.λz.z) because this term is definitionally the Church zero. Rule S-Self-Gen gives the self type Nat.

For successor, assume n:Nat. By S-Self-Inst, n:C:NatU0.(k:Nat.C(k)C(S(k)))C(0)C(n). Thus nsz:C(n) and sn(nsz):C(S(n)). Abstraction gives the body required for S(n), and S-Self-Gen gives S(n):Nat. ◻

Theorem 94.5 — Derived natural-number induction

The Curry term ind:=λs.λz.λn.nsz has type C:NatU0.(n:Nat.C(n)C(S(n)))C(0)n:NatC(n).

Proof of Theorem 94.5 — Derived natural-number induction

Proof. Fix C, s, z, and n:Nat. Rule S-Self-Inst gives exactly the implicit product displayed in the first paragraph of lemma 94.4. Three eliminations yield nsz:C(n). Abstraction over n, z, and s, followed by the implicit introduction for C, gives the stated type. The type of the final result mentions the function argument n because self instantiation substituted that same subject for x. ◻

The constructor computations occur after erasure: ind s z 0βz,ind s z (Sn)βsn(nsz). For a neutral n, nsz remains stuck even though its type is C(n).

Exercise 94.2

★★☆ Fix A:U0. Work in context n:Nat with the indexed closure Vec(A,n)ιv.C:(k:NatVec(A,k)U0).C(0,vnil)(k:Nat.a:A.xs:Vec(A,k).C(k,xs)C(S(k),vcons(k,a,xs)))C(n,v). Give fully typed Church terms for vnil and vcons under this closure. Then derive the exact result type n:Natv:Vec(A,n)C(n,v) of the induction term, including the nil and cons premises displayed above and the final self-instantiation step.

Metatheory at the frozen signature

Lemma 94.6 — System S substitution

If Γ,x:A,Δt:T and Γu:A, then Γ,Δ[u/x]t[u/x]:T[u/x].

Proof of Lemma 94.6 — System S substitution

Proof. Induct on the typing derivation. The implicit-product cases choose their bound variable outside FV(u)FV(Γ)FV(Δ) and apply the induction hypothesis under that binder. In the S-Self-Gen case, the induction hypothesis gives t[u/x]:T[t/y][u/x]. Choose the self binder y outside FV(u). Capture avoidance gives T[t/y][u/x]=T[u/x][t[u/x]/y], which is the premise of S-Self-Gen for ιy.T[u/x]. The S-Self-Inst case uses the same equation in the opposite direction. Closure entries are closed, so substitution does not alter their right-hand sides. ◻

Theorem 94.7 — Confluence and preservation

In a well-formed System S closure, beta reduction on terms and types is confluent. If Γt:T and tβt, then Γt:T.

Proof of Theorem 94.7 — Confluence and preservation

Proof. This is an exact import for the signature of convention 94.1. Fu and Stump prove confluence of beta reduction as Lemma 1 on page 12. Their self-conversion relation and ι-elimination theorem are Definition 15 and Theorem 6 on pages 11–12. Definitions 17–20 and Lemmas 3–7 on page 13 define the term- and type-morphing substitutions and prove product compatibility as Theorem 7. Theorem 8 on that page then has the signature Γt:T,Γtβt,ΓwfΓt:T. These imported results give the two clauses of the theorem; no theorem is transferred to mutual, open, or nonpositive closure entries [FS14]. ◻

Theorem 94.8 — Strong normalization of System S

If Γwf and Γt:T in the frozen System S signature, then t is strongly normalizing for beta reduction.

Proof of Theorem 94.8 — Strong normalization of System S

Proof. Import the exact erasure and reducibility development of Fu and Stump. On page 10, Definitions 8–11 give the target Fω signature with positive definitions and the kind, type, and context erasures; Theorem 4 proves that a well-formed System S derivation maps to that target. On page 11, Definitions 12–14 give the reducibility candidates, the least-fixed-point environment for positive recursive definitions, and the logical relation. Theorem 5 states that if Γt:T and Γwf, then the unchanged Curry term belongs to the candidate interpreting the erased T. The sentence immediately following Theorem 5 combines it with Theorem 4 to conclude strong normalization. Those results have exactly the closure and positivity hypotheses frozen here, so they establish the displayed statement [FS14]. ◻

If the positivity hypothesis is removed, Bad above and δδ invalidate the fixed-point interpretation and the conclusion. If mutual recursion or open closure right-hand sides are added, the displayed translation no longer proves the theorem; a separate target metatheory would be required.

Four distinct self binders

System self binder occurs in enabling rule erasure
dependent intersection second view B(x) same-subject introduction one existing term
System S the assigned type T(x) self generation/instantiation unchanged term
OO Self method result types class/matching rules object value
DOT recursive object type recursive introduction/path selection allocated object

An identity self-loop instead has a path variable p:x=Ax and an identity eliminator. System S has neither endpoints nor path elimination. Its normalization proof depends on the positive recursive closure and on erasure, not on a groupoid law.

Suggested first pass.

Begin with exercise 94.3, then complete exercise 94.5.

Exercise 94.3

★★☆ Write the complete typing derivation of indszn:C(n). Circle the occurrence of n introduced by S-Self-Inst. Replace C(n) by a constant motive and identify the ordinary Church iterator obtained after erasure.

Exercise 94.4

★★☆ Compute the polarity of the recursive variable in 1+X×X, XN, and (XN)N. For each result, state whether the frozen closure admits it. For the rejected case, show the failed reducibility-candidate monotonicity inclusion.

Exercise 94.5

★★★ Practical project.system-s-self-positivity-checker Implement in Kappa a finite polarity checker for products and arrows, together with a finite same-subject check for self generation and instantiation. Maintain two invariants: both self rules preserve the subject’s erased tag, and every accepted recursive occurrence is positive. Accept X×X and (X1)1, reject X1, and reject a self-instantiation whose displayed subject differs from the substituted subject. Removing the arrow-domain polarity flip must make the test fail.

Sources. The System S syntax and rules are on pages 5–7 of Fu and Stump’s extended version; the Church-natural derivation is on pages 7–8. The erasure to Fω with positive definitions begins on pages 9–11, the confluence and morph analyses on pages 11–13, and preservation and consistency on pages 13–14. The source proves strong normalization only for its restricted closure discipline. No public System S checker or mechanized metatheory was available, so the Kappa project tests the printed side conditions rather than claiming to mechanize the theorem [FS14].

Search the book

Type to search the local edition.