Prerequisites. Direct starred prerequisites: none. No later core chapter depends on this route.
Typed self-representation without a paradox ⋆
Strong normalization appears to forbid a self-interpreter. An interpreter which can consume its own text seems to invite the same diagonal argument which proves that there is no total computable universal function for the total computable functions. The conclusion is too quick. The diagonal argument needs one particular self-application to be well typed, and a typed representation is indexed precisely so that this application need not be well typed.
The diagonal step that typing refuses
Let us recall the classical argument in the form that matters here. Suppose that a total computable function U:ℕ×ℕ⟶ℕ were universal for total computable unary functions: for every such function 𝑓 there would be an index 𝑎 with 𝑓(𝑛) =U(𝑎,𝑛) for all 𝑛. Then 𝑑(𝑛):=U(𝑛,𝑛)+1 would itself be total and computable. If 𝑎 indexed 𝑑, then 𝑑(𝑎) =U(𝑎,𝑎) +1 =𝑑(𝑎) +1, a contradiction. The two occurrences of 𝑎 in U(𝑎,𝑎) are the whole mechanism.
Here is the corresponding calculation for terms. A quotation is provisionally the result of an external operation on a chosen closed typing derivation D :𝑒 :𝐴; write its result as ̂D, or temporarily as ̂𝑒 when the derivation is fixed. Suppose that a closed internal term 𝑢 unquotes every genuine quotation: 𝑢̂𝑒=𝛽𝑒. Suppressing annotations for the moment, form 𝑝𝑢:=𝜆𝑥.𝜆𝑦.(𝑢𝑥)𝑥. The vacuous binder 𝜆𝑦 plays the role of the classical +1: it makes the diagonal reduct differ from itself by exactly one abstraction node. If ̂𝑝𝑢 exists and the diagonal application 𝑝𝑢 ̂𝑝𝑢 is typable, then 𝑝𝑢̂𝑝𝑢⟶𝛽𝜆𝑦.(𝑢̂𝑝𝑢)̂𝑝𝑢=𝛽𝜆𝑦.𝑝𝑢̂𝑝𝑢. The equation looks paradoxical, but only after the italicized typing assumption has been made.
The barrier argument needs unique normal forms for a relation that also normalizes constructor annotations. Let ⟹𝛽 be the compatible closure, through a term, of term beta contraction and constructor beta contraction in annotations and type arguments. Write ≡mix𝛽 for its symmetric, transitive closure. To obtain unique normal forms, it remains to prove that two reductions from one term can be joined. Root and congruence reduction overlap at beta-redexes, so the joining relation must commute with both term and constructor substitution.
Let ⇛c be parallel constructor beta reduction: it has reflexivity, congruence for every constructor former, and the root clause 𝐴⇛c𝐴′𝐶⇛c𝐶′(𝜆𝑢::𝜅.𝐴)𝐶⇛c𝐴′[𝐶′/𝑢]. Let ⇛m contain reflexivity, congruence for term abstraction, application, type abstraction, and type application, together with the ordinary term-beta root and the following type-beta root. Its annotations and type arguments reduce by ⇛c: 𝑒⇛m𝑒′𝑑⇛m𝑑′(𝜆𝑥:𝐴.𝑒)𝑑⇛m𝑒′[𝑑′/𝑥],𝑒⇛m𝑒′𝐶⇛c𝐶′(Λ𝑢::𝜅.𝑒)[𝐶]⇛m𝑒′[𝐶′/𝑢]. After capture-avoiding freshening, the following simultaneous substitution laws hold: 𝑒⇛m𝑒′, 𝑑⇛m𝑑′⟹𝑒[𝑑/𝑥]⇛m𝑒′[𝑑′/𝑥],𝑒⇛m𝑒′, 𝐶⇛c𝐶′⟹𝑒[𝐶/𝑢]⇛m𝑒′[𝐶′/𝑢]. Both parallel relations have the diamond property.
Referenced from 4 locations
Proof of Lemma 17.1 — Mixed parallel substitution and diamond
Proof. The first substitution law is the induction of lemma 5.37; its abstraction case additionally uses constructor congruence on the binder annotation. Prove the second by induction on 𝑒 ⇛m𝑒′. Constructor annotations and type arguments use constructor substitution. In the term-beta case, constructor substitution commutes with capture-avoiding term substitution. The only new root calculation is type beta. Alpha-rename its binder 𝑣 so that 𝑣 ∉{𝑢} ∪FV(𝐶) ∪FV(𝐶′). The two orders are identified by 𝑒0[𝐷/𝑣][𝐶/𝑢]=𝑒0[𝐶/𝑢][𝐷[𝐶/𝑢]/𝑣], and the induction hypotheses reduce both sides in parallel to
𝑒′0[𝐷′/𝑣][𝐶′/𝑢]=𝑒′0[𝐶′/𝑢][𝐷′[𝐶′/𝑢]/𝑣].
For the diamonds, use the source-form complete development. Its complete term clauses are 𝑥∙:=𝑥,(𝜆𝑥:𝐴.𝑒)∙:=𝜆𝑥:𝐴∙.𝑒∙,(Λ𝑢::𝜅.𝑒)∙:=Λ𝑢::𝜅.𝑒∙,((𝜆𝑥:𝐴.𝑏)𝑑)∙:=𝑏∙[𝑑∙/𝑥],((Λ𝑢::𝜅.𝑒)[𝐶])∙:=𝑒∙[𝐶∙/𝑢],(𝑒1𝑒2)∙:=𝑒∙1𝑒∙2when 𝑒1 is not syntactically an abstraction,(𝑒[𝐶])∙:=𝑒∙[𝐶∙]when 𝑒 is not syntactically a type abstraction. where the two application clauses and the two type-application clauses are selected by the source outer form. An annotation or type argument is developed by constructor complete development, whose complete clauses are 𝑢∙:=𝑢,(𝐴→𝐵)∙:=𝐴∙→𝐵∙,(∀𝑢::𝜅.𝐴)∙:=∀𝑢::𝜅.𝐴∙,(𝜆𝑢::𝜅.𝐴)∙:=𝜆𝑢::𝜅.𝐴∙,((𝜆𝑢::𝜅.𝐴)𝐶)∙:=𝐴∙[𝐶∙/𝑢],(𝐴𝐶)∙:=𝐴∙𝐶∙. The last clause applies when 𝐴 is not syntactically a constructor abstraction. These clauses are exhaustive for the displayed term and constructor grammars. In particular, constructor application contracts only a source of the displayed beta form and otherwise develops the two components without contracting their result. Thus development does not contract a redex created by developing an immediate component. Induction on a parallel derivation shows that every parallel reduct takes one further parallel step to this complete development. For application congruence, split on the source outer form of 𝑒1. If 𝑒1 is not an abstraction, from 𝑒𝑖 ⇛m𝑒′𝑖 the induction hypotheses give 𝑒′𝑖 ⇛m𝑒∙𝑖, hence 𝑒′1𝑒′2 ⇛m𝑒∙1𝑒∙2, the complete development. If 𝑒1 =𝜆𝑥 :𝐴.𝑏, then 𝑒′1 =𝜆𝑥 :𝐴′.𝑏′ for parallel reducts 𝐴′,𝑏′. Apply the root clause to 𝑒′1𝑒′2 and the substitution law to reach 𝑏∙[𝑒∙2/𝑥], the complete development of the source application. A constructor root–congruence overlap at (𝜆𝑢.𝐴)𝐶 joins at 𝐴∙[𝐶∙/𝑢] by constructor substitution. A term root–congruence overlap at (𝜆𝑥 :𝐴.𝑒)𝑑 joins at 𝑒∙[𝑑∙/𝑥] by the first displayed law. Finally, the new overlap at (Λ𝑢 ::𝜅.𝑒)[𝐶] joins at 𝑒∙[𝐶∙/𝑢] by the second law. These are the only root overlaps. Thus every parallel reduct of 𝑎 takes one parallel step to 𝑎∙. Fix either of the two parallel relations. If 𝑎 reduces in parallel to both 𝑏 and 𝑐, then both 𝑏 and 𝑐 reduce in parallel to 𝑎∙. This proves the diamond property for each relation. ◻
Proof of Lemma 7.56 — Term normalization and confluence used here
Proof. The source proves strong normalization of every well-typed term in the pure 𝐹𝜔 signature under combined beta reduction [Bar92]. This relation contracts both term-level and constructor-level beta redexes; on the separated syntax printed here it is exactly ⟹𝛽. The term-only relation is a subrelation. Expanding a named abbreviation adds no reduction rule.
By lemma 17.1, mixed parallel reduction is diamond. Every mixed one-step contraction is parallel, and every parallel step can be serialized into finitely many compatible mixed steps, by induction on its derivation. The path-length argument of theorem 5.38 therefore gives mixed confluence. Restricting the parallel clauses to term roots and holding annotations and type arguments fixed gives term-only confluence. ◻
Let 𝑢 be a closed 𝐹𝜔 term which unquotes the quotation of every closed, well-typed 𝐹𝜔 term. Suppose annotations can be chosen so that 𝑝𝑢:=𝜆𝑥.𝜆𝑦.(𝑢 𝑥)𝑥 is closed and well typed, and its quotation ̂𝑝𝑢 exists. Then 𝑝𝑢 ̂𝑝𝑢 is not a well-typed 𝐹𝜔 term. The conclusion holds for either the term-beta equation 𝑢 ̂𝑒 =𝛽𝑒 or its mixed-beta analogue.
Referenced from 4 locations
Proof of Proposition 7.57 — The normalization barrier, exactly stated
Proof. Fix either relation from the statement. Assume that the application is well typed. Its first term-beta reduct is well typed by subject reduction. The unquoting hypothesis relates 𝑢 ̂𝑝𝑢 to 𝑝𝑢 in the chosen relation. Compatible congruence under application and abstraction therefore relates 𝜆𝑦.(𝑢 ̂𝑝𝑢) ̂𝑝𝑢 to 𝜆𝑦.𝑝𝑢 ̂𝑝𝑢; this is the second step of (7.6).
By lemma 7.56, let 𝑣 be the normal form of 𝑝𝑢 ̂𝑝𝑢 in the chosen relation. Confluence says that equivalent well-typed terms have alpha-equivalent normal forms. Compatible reduction under the outer abstraction gives 𝜆𝑦.𝑣 as the normal form of the last term in (7.6). Hence 𝑣 would be alpha-equivalent to 𝜆𝑦.𝑣. This is impossible: the latter finite syntax tree contains one more abstraction node. Therefore the diagonal application is not well typed. ◻
The proposition does not say that 𝑢 is untypable. It does not even say that 𝑝𝑢 is untypable. It says that the represented type attached to ̂𝑝𝑢 does not permit the second use of the same argument required by the diagonal. This is the point at which the analogy with one untyped universal domain ends.
The proposition is conditional. Its antecedent is not a property of the deep indexed representation. Its unquoter has type 𝗎𝗇𝗊𝗎𝗈𝗍𝖾:∀𝛼::𝑈.𝖤𝗑𝗉𝛼→𝖮𝗉𝖨𝖽𝛼. Under 𝛼 ::𝑈 and 𝑥 :𝖤𝗑𝗉 𝛼, the attempted body (𝗎𝗇𝗊𝗎𝗈𝗍𝖾[𝛼]𝑥)𝑥 would require constructor conversion 𝖮𝗉𝖨𝖽𝛼=𝛽𝖤𝗑𝗉𝛼→𝐵 for some 𝐵. Unfolding 𝖮𝗉 gives the two contractions 𝖮𝗉𝖨𝖽𝛼⇝0𝖨𝖽(𝛼𝖨𝖽)⇝0𝛼𝖨𝖽. The result has neutral constructor head 𝛼, so its constructor normal form cannot have arrow head. Strong normalization and unique constructor normal forms theorem 7.21, corollary 7.24 reject the application before any term reduction occurs. At a genuine closed index 𝛼 =̂𝐴, the same result type reduces to 𝐴, which is exactly why ordinary unquotation remains typable. Here and until the formal construction below, ̂𝐴 denotes a constructor of kind 𝑈; it is distinct from the term quotation ̂𝑒.
★★☆ Work under 𝛼 ::𝑈 and 𝑥 :𝖤𝗑𝗉 𝛼. Infer the type of 𝗎𝗇𝗊𝗎𝗈𝗍𝖾[𝛼]𝑥, then show that applying this result to 𝑥 would require 𝖮𝗉 𝖨𝖽 𝛼 =𝛽𝖤𝗑𝗉 𝛼 →𝐵. Normalize both constructor heads and explain why neutral 𝛼 cannot be converted to an arrow. Then substitute ̂𝐴 for 𝛼 and use lemma 7.66 to show why unquoting a genuine quotation at 𝐴 is nevertheless well typed. This is a constructor-typing calculation; do not appeal to term strong normalization.
Referenced from 3 locations
The pure calculus
Quotation and unquotation use the pure 𝐹𝜔 fragment generated by 𝜅::=𝖳𝗒∣𝜅1→𝜅2,𝐴,𝐵::=𝑢∣𝐴→𝐵∣∀𝑢::𝜅.𝐴∣𝜆𝑢::𝜅.𝐴∣𝐴𝐵,𝑒::=𝑥∣𝜆𝑥:𝐴.𝑒∣𝑒𝑒∣Λ𝑢::𝜅.𝑒∣𝑒[𝐴] with the kinding and typing rules of chapter 9. Constructor conversion is type-level beta conversion. Compatible term reduction has the two root contractions (𝜆𝑥:𝐴.𝑒1)𝑒2⟶𝛽𝑒1[𝑒2/𝑥],(Λ𝑢::𝜅.𝑒)[𝐶]⟶𝛽𝑒[𝐶/𝑢] and is closed under binders and both operands of an application. A term is normal when its term tree contains neither root; constructor redexes in type annotations and type arguments do not affect this predicate.
Write 𝑒 ≈ty𝑒′ when 𝑒 and 𝑒′ have the same term tree and corresponding constructor components are beta-convertible. For the term-only closure ⟶∗𝛽 and the mixed reduction ⟹𝛽 fixed before lemma 17.1, 𝑒⟶∗𝛽𝑒′⟹𝑒⟹∗𝛽𝑒′,𝑒≈ty𝑒′⟹𝑒≡mix𝛽𝑒′. Deep unquotation reduces by ⟹∗𝛽 to the source term. Restricting the calculation to ⟶𝛽 instead yields some 𝑒′ with 𝑒′ ≈ty𝑒: constructor normalization may change annotations, but not the term tree or its normality.
Names such as 𝖡𝗈𝗈𝗅 and 𝖭𝖺𝗍 abbreviate the Church encodings 𝖡𝗈𝗈𝗅𝐹 and 𝖭𝖺𝗍𝐹 of definition 5.15, definition 5.18, with explicit kind annotations. Every named declaration in this chapter expands to one term of the stated grammar. A constructor binder without an explicit kind in a program formula has kind 𝖳𝗒; term binders retain their type annotations.
A shallow representation
The quotation must be beta-normal while substituting a fixed identity must recover the source. Copying the source under a fresh binder does not meet the first requirement: for the redex (𝜆𝑥 :𝐴.𝑥)𝑦, the naive candidate 𝜆𝑖:𝐼.(𝜆𝑥:𝐴.𝑥)𝑦 still contains that redex. The repair is to record each application under an inert variable head, so that the application node becomes stuck until unquotation replaces the inert variable by the identity. Put 𝐼:=∀𝑍::𝖳𝗒.𝑍→𝑍,𝑖:𝐼. The letter 𝑖 is a fresh, designated term variable. Quotation is defined on a typing derivation, rather than on an unannotated term, because an application node must record the function type found by that derivation.
For a derivation D of Δ;Γ ⊢𝑒 :𝐴, the shallow prequotation relation D ⇝sh𝑞 is determined by the following clauses. If the final rule of D is application, its premises derive 𝑒1 :𝐴 →𝐵 and 𝑒2 :𝐴; the clause therefore builds an application representation of type 𝐵. 𝑥⇝sh𝑥,𝜆𝑥:𝐴.𝑒⇝sh𝜆𝑥:𝐴.𝑞,(𝑒⇝sh𝑞),𝑒1𝑒2⇝sh𝑖[𝐴→𝐵]𝑞1𝑞2,𝑒1:𝐴→𝐵⇝sh𝑞1,𝑒2:𝐴⇝sh𝑞2,}Λ𝑢::𝜅.𝑒⇝shΛ𝑢::𝜅.𝑞,(𝑒⇝sh𝑞),𝑒[𝐶]⇝sh𝑖[∀𝑢::𝜅.𝐴]𝑞[𝐶],(𝑒:∀𝑢::𝜅.𝐴⇝sh𝑞). A final use of conversion leaves 𝑞 unchanged. For a closed derivation D of 𝑒 :𝐴, its shallow quotation is the term ̂Dsh:=𝜆𝑖:𝐼.𝑞.
Referenced from 2 locations
The application clauses are easy to read by calculation. Since 𝑖 is a variable, 𝑖[𝐴→𝐵]𝑞1𝑞2and𝑖[∀𝑢::𝜅.𝐴]𝑞[𝐶] are stuck, hence normal, yet replacing 𝑖 by the polymorphic identity erases the inserted node in either case.
If D derives Δ;Γ ⊢𝑒 :𝐴 and D ⇝sh𝑞, then Δ;Γ,𝑖:𝐼⊢𝑞:𝐴. If D is closed, then ̂Dsh :𝐼 →𝐴 and ̂Dsh is term-beta-normal.
Referenced from 2 locations
Proof of Lemma 7.59 — Typing and normality of shallow quotation
Proof. Induct on the typing derivation. The variable, term-abstraction, and type-abstraction cases use the same typing rule as the source derivation and the induction hypothesis for the immediate premise.
For term application the two induction hypotheses give 𝑞1 :𝐴 →𝐵 and 𝑞2 :𝐴. The variable 𝑖 has the instances 𝑖[𝐴→𝐵]:(𝐴→𝐵)→(𝐴→𝐵),𝑖[𝐴→𝐵]𝑞1:𝐴→𝐵, so 𝑖[𝐴 →𝐵]𝑞1𝑞2 :𝐵. For type application the induction hypothesis gives 𝑞 :∀𝑢 ::𝜅.𝐴, and 𝑖[∀𝑢::𝜅.𝐴]𝑞:∀𝑢::𝜅.𝐴; applying this term to 𝐶 gives 𝐴[𝐶/𝑢]. A final conversion changes only the claimed result type.
Now assume the derivation closed. Abstracting 𝑖 gives type 𝐼 →𝐴. For normality, induct once more over the same clauses. A copied abstraction cannot introduce a redex. At either application clause the head is the variable 𝑖, not an abstraction; the induction hypotheses say that all proper term subexpressions are normal. The conversion case changes no term. For a term abstraction Γ,𝑥 :𝐴 ⊢𝑒 :𝐵, the body induction hypothesis holds under 𝑥 :𝐴; copying the binder therefore gives type 𝐴 →𝐵 without introducing a redex. ◻
Define the closed polymorphic identity and the internal shallow unquoter by 𝗂𝖽𝐼:=Λ𝑍::𝖳𝗒.𝜆𝑧:𝑍.𝑧:𝐼,𝗎𝗇𝗊𝗎𝗈𝗍𝖾sh:=Λ𝐴::𝖳𝗒.𝜆𝑟:𝐼→𝐴.𝑟𝗂𝖽𝐼:∀𝐴::𝖳𝗒.(𝐼→𝐴)→𝐴. Unlike quotation, this is an ordinary term of 𝐹𝜔.
If D is a closed derivation of 𝑒 :𝐴, then 𝗎𝗇𝗊𝗎𝗈𝗍𝖾sh[𝐴]̂Dsh⟶∗𝛽𝑒.
Referenced from 3 locations
Proof of Theorem 7.60 — Strong shallow unquoting
Proof. After the outer type contraction and two term contractions it is enough to prove the stronger assertion 𝑞[𝗂𝖽𝐼/𝑖]⟶∗𝛽𝑒(†) for every shallow prequotation. We induct on its typing derivation. A variable is unchanged. Term and type abstractions follow by compatible reduction under the binder and the corresponding induction hypothesis.
For term application, the decisive part of the calculation is 𝗂𝖽𝐼[𝐴→𝐵]𝑞′1𝑞′2⟶∗𝛽𝑞′1𝑞′2⟶∗𝛽𝑒1𝑒2, where 𝑞′𝑗 =𝑞𝑗[𝗂𝖽𝐼/𝑖] and the last reductions are the two induction hypotheses. Type application calculates 𝗂𝖽𝐼[∀𝑢::𝜅.𝐴]𝑞′[𝐶]⟶∗𝛽𝑞′[𝐶]⟶∗𝛽𝑒[𝐶]. A final conversion added no syntax, so it uses the induction hypothesis unchanged. This proves ( †) and hence the theorem. ◻
★★☆ Take 𝐴 =𝐼 and 𝑎 =𝗂𝖽𝐼. Write the complete shallow prequotation of (𝜆𝑥 :𝐼.𝑥) 𝗂𝖽𝐼, including the inserted type argument to 𝑖 and its two term arguments. Then substitute 𝗂𝖽𝐼 and display every beta step to the original redex. Explain why the quotation itself is normal even though the represented term is not.
Referenced from 3 locations
The shallow construction already breaks through the normalization barrier: the unquoter terminates and returns the represented term. It is too opaque for a size function, however. Its interface exposes no constructor tag or case operator: a consumer can only apply the stored polymorphic term at a chosen result type. A direct inspection of beta-eta normal forms therefore offers no branch that can count the source constructor. To inspect the four term constructors we must expose four cases in the representation itself.
Representing types only as far as the fold needs
Fix a fresh constructor variable 𝐹 ::𝖳𝗒 →𝖳𝗒. Marking every constructor production is too strong. For constructor application it would give 𝗉𝗋𝖾all𝐹(𝐴𝐵)=𝐹(𝗉𝗋𝖾all𝐹(𝐴)𝗉𝗋𝖾all𝐹(𝐵)), but the argument of the outer 𝐹 must already have kind 𝖳𝗒, whereas 𝐴 may have an arrow kind; the application case of the formation induction cannot be rebuilt. Constructor variables, abstractions, and applications must retain their kind, while the arrow and universal productions receive the marker. The 𝐹-pre-representation of a constructor is defined structurally: the constructor translation 𝗉𝗋𝖾𝐹(𝐴) is a syntactic constructor of representation kind. A semantic interpretation such as [[𝐴]]𝜌 instead maps a type to a relation. They are different constructions, and no theorem identifying them is asserted here. 𝗉𝗋𝖾𝐹(𝑢)=𝑢,𝗉𝗋𝖾𝐹(𝐴→𝐵)=𝐹𝗉𝗋𝖾𝐹(𝐴)→𝐹𝗉𝗋𝖾𝐹(𝐵),𝗉𝗋𝖾𝐹(∀𝑢::𝜅.𝐴)=∀𝑢::𝜅.𝐹𝗉𝗋𝖾𝐹(𝐴),𝗉𝗋𝖾𝐹(𝜆𝑢::𝜅.𝐴)=𝜆𝑢::𝜅.𝗉𝗋𝖾𝐹(𝐴),𝗉𝗋𝖾𝐹(𝐴𝐵)=𝗉𝗋𝖾𝐹(𝐴)𝗉𝗋𝖾𝐹(𝐵). The full representation of a closed constructor is ̂𝐴:=𝜆𝐹::𝖳𝗒→𝖳𝗒.𝗉𝗋𝖾𝐹(𝐴). Here ̂𝐴 is a constructor of kind 𝑈. By contrast, ̂D is a term quotation determined by the typing derivation D, and ̂𝑒 abbreviates that term only after its derivation has been fixed. The hat records representation in each case, while the sort of its operand determines whether the result is a constructor or a term. Notice the asymmetry in (7.7). An arrow or universal type classifies terms and is therefore marked by 𝐹; a constructor variable, constructor abstraction, or constructor application is represented by itself. This is enough information to calculate the result type of each operation; it is not an inductive syntax tree for types.
Let 𝐹 be fresh.
If Δ ⊢𝐴 ::𝜅, then Δ,𝐹 ::𝖳𝗒 →𝖳𝗒 ⊢𝗉𝗋𝖾𝐹(𝐴) ::𝜅.
If Δ,𝑢 ::𝜅 ⊢𝐴 ::𝜅′ and Δ ⊢𝐶 ::𝜅, then, up to renaming of bound variables, 𝗉𝗋𝖾𝐹(𝐴[𝐶/𝑢])=𝗉𝗋𝖾𝐹(𝐴)[𝗉𝗋𝖾𝐹(𝐶)/𝑢].
If 𝐴 =𝛽𝐵, then 𝗉𝗋𝖾𝐹(𝐴) =𝛽𝗉𝗋𝖾𝐹(𝐵).
Consequently, if 𝐴 is closed of kind 𝜅, then ̂𝐴 ::(𝖳𝗒 →𝖳𝗒) →𝜅. In particular, for a closed type 𝐴, ̂𝐴::𝑈,𝑈:=(𝖳𝗒→𝖳𝗒)→𝖳𝗒.
Referenced from 3 locations
Proof of Lemma 7.61 — Formation and substitution of type pre-representations
Proof. For (1), induct on the kinding derivation. A variable is unchanged. In an arrow, the induction hypotheses give 𝗉𝗋𝖾𝐹(𝐴),𝗉𝗋𝖾𝐹(𝐵) ::𝖳𝗒; applying 𝐹 to each gives two types and hence their arrow is a type. In a universal, the body hypothesis gives 𝗉𝗋𝖾𝐹(𝐴) ::𝖳𝗒 under 𝑢 ::𝜅, so 𝐹 𝗉𝗋𝖾𝐹(𝐴) ::𝖳𝗒 and the universal is formed. Constructor abstraction and application use their two kinding rules directly. Thus variables, arrows, universals, constructor abstractions, and constructor applications each preserve kind 𝖳𝗒 under prequotation.
For (2), induct on 𝐴. For an arrow, 𝗉𝗋𝖾𝐹((𝐴→𝐵)[𝐶/𝑢])=𝐹𝗉𝗋𝖾𝐹(𝐴[𝐶/𝑢])→𝐹𝗉𝗋𝖾𝐹(𝐵[𝐶/𝑢]), and the two induction hypotheses rewrite this to 𝗉𝗋𝖾𝐹(𝐴→𝐵)[𝗉𝗋𝖾𝐹(𝐶)/𝑢]. Variables and applications are homomorphic. Under either binder, first rename its bound variable away from 𝑢 and the free variables of 𝐶, then apply the induction hypothesis to the body. This accounts for both constructor abstraction and universal quantification.
For (3), it suffices by congruence to inspect one constructor beta step. By (2), 𝗉𝗋𝖾𝐹((𝜆𝑢::𝜅.𝐴)𝐶)=(𝜆𝑢::𝜅.𝗉𝗋𝖾𝐹(𝐴))𝗉𝗋𝖾𝐹(𝐶)→𝛽𝗉𝗋𝖾𝐹(𝐴)[𝗉𝗋𝖾𝐹(𝐶)/𝑢]=𝗉𝗋𝖾𝐹(𝐴[𝐶/𝑢]). The conclusion about ̂𝐴 is now one use of constructor abstraction. ◻
Type application creates a difficulty that did not occur in the shallow representation. If 𝑒 :∀𝑢 ::𝜅.𝐴, its representation has to remember how to obtain the instance at 𝐶. We record that relationship extensionally by the ordinary term 𝗂𝗇𝗌𝗍𝑃,𝑄:=𝜆𝑥:𝑃.𝑥[𝑄]:𝑃→𝐵[𝑄/𝑢],𝑃=∀𝑢::𝜅.𝐵,𝑄::𝜅. The notation is defined only when 𝑃 has the displayed universal form and 𝑄 has the displayed kind. It is not a kind-polymorphic 𝐹𝜔 function; each occurrence in a quotation is a separately constructed term.
Type abstraction creates the dual difficulty. Its body has a redundant quantifier after the constant-result folds used by 𝗌𝗂𝗓𝖾 and 𝗂𝗌𝖭𝗈𝗋𝗆𝖺𝗅. Concretely, under a constant fold 𝐾𝑋 =𝜆𝐴.𝑋, the recursive value has type 𝑥 :∀𝑢 ::𝜅.𝑋, while the case branch must return 𝑋. It suffices to instantiate 𝑥 at one fixed constructor of kind 𝜅. The type 𝖲𝗍𝗋𝗂𝗉 records this operation uniformly. Every kind has such a closed constructor: 𝑆𝖳𝗒:=∀𝑋::𝖳𝗒.𝑋,𝑆𝜅1→𝜅2:=𝜆𝑢::𝜅1.𝑆𝜅2. The kinding judgment ⊢𝑆𝜅 ::𝜅 follows by induction on 𝜅. At the base kind the concrete calculation is one use of K-All: 𝑋::𝖳𝗒⊢𝑋::𝖳𝗒⟹⊢∀𝑋::𝖳𝗒.𝑋::𝖳𝗒. For the arrow step, the induction hypothesis gives ⊢𝑆𝜅2 ::𝜅2; weakening places it under 𝑢 ::𝜅1, and K-Abs derives ⊢𝜆𝑢 ::𝜅1.𝑆𝜅2 ::𝜅1 →𝜅2. This claims a closed constructor of kind 𝖳𝗒, not a closed term inhabiting that type. Put 𝖲𝗍𝗋𝗂𝗉:=𝜆𝐹::𝖳𝗒→𝖳𝗒.𝜆𝐴::𝖳𝗒.∀𝐵::𝖳𝗒.(∀𝐶::𝖳𝗒.𝐹𝐶→𝐵)→𝐴→𝐵. If 𝑇 ::𝜅 →𝖳𝗒, define 𝗌𝗍𝗋𝗂𝗉𝐹,𝜅,𝑇:=Λ𝐵::𝖳𝗒.𝜆𝑐:(∀𝐶::𝖳𝗒.𝐹𝐶→𝐵).𝜆𝑥:(∀𝑢::𝜅.𝐹(𝑇𝑢)).𝑐[𝑇𝑆𝜅](𝑥[𝑆𝜅]). Then 𝗌𝗍𝗋𝗂𝗉𝐹,𝜅,𝑇:𝖲𝗍𝗋𝗂𝗉𝐹(∀𝑢::𝜅.𝐹(𝑇𝑢)). Indeed, 𝑥[𝑆𝜅] :𝐹(𝑇𝑆𝜅) and 𝑐[𝑇𝑆𝜅] :𝐹(𝑇𝑆𝜅) →𝐵. This two-line derivation is the reason for the otherwise arbitrary-looking inhabitant 𝑆𝜅.
For later calculations record what stripping does when 𝐹 is the constant function 𝐾𝑋:=𝜆𝐴 ::𝖳𝗒.𝑋 and the combining map is the identity: 𝗌𝗍𝗋𝗂𝗉𝐾𝑋,𝜅,𝑇[𝑋](Λ𝐶::𝖳𝗒.𝜆𝑧:𝑋.𝑧)(Λ𝑢::𝜅.𝑞)⟶∗𝛽𝑞[𝑆𝜅/𝑢]. Thus stripping does not erase an arbitrary quantified value. It chooses one well-kinded instance. This is sufficient only when the operation’s answer is independent of type arguments, as size and normality are.
★★★ Work in the constructor context 𝑋 ::𝖳𝗒,𝑇 ::𝜅 →𝖳𝗒, where 𝐾𝑋:=𝜆𝐴 ::𝖳𝗒.𝑋, and take 𝜅 =(𝖳𝗒 →𝖳𝗒) →𝖳𝗒. Expand 𝑆𝜅, derive its kind, and type every subterm of 𝗌𝗍𝗋𝗂𝗉𝐾𝑋,𝜅,𝑇. Finally verify (7.10) for this kind by an explicit reduction.
Hint. First derive 𝑆𝖳𝗒 ::𝖳𝗒, then use one constructor abstraction with a binder of kind 𝖳𝗒 →𝖳𝗒 to derive 𝑆𝜅 ::𝜅. In the body, type 𝑥[𝑆𝜅] before instantiating 𝑐 at 𝑇 𝑆𝜅.
Referenced from 3 locations
The deep representation and its fold
The naive type-abstraction case would quantify over the represented binder’s kind: ∀𝜅.(∀𝑢::𝜅.𝐹(𝑇𝑢))→𝐹(∀𝑢::𝜅.𝑇𝑢). This is not a constructor of pure 𝐹𝜔: kinds are not first-class and there is no ∀𝜅. The case type must instead work for each fixed metalevel kind 𝜅, and receive the uniform stripping operation that extracts a representative body at that kind. The same obstruction determines the type-application case. The repair assigns one case type to each syntactic constructor, recording the represented source and target types in its indices: 𝖮𝗉:=𝜆𝐹::𝖳𝗒→𝖳𝗒.𝜆𝛼::𝑈.𝐹(𝛼𝐹),𝖠𝖻𝗌:=𝜆𝐹::𝖳𝗒→𝖳𝗒.∀𝑃::𝖳𝗒.∀𝑄::𝖳𝗒.(𝐹𝑃→𝐹𝑄)→𝐹(𝐹𝑃→𝐹𝑄),𝖠𝗉𝗉:=𝜆𝐹::𝖳𝗒→𝖳𝗒.∀𝑃::𝖳𝗒.∀𝑄::𝖳𝗒.𝐹(𝐹𝑃→𝐹𝑄)→𝐹𝑃→𝐹𝑄,𝖳𝖠𝖻𝗌:=𝜆𝐹::𝖳𝗒→𝖳𝗒.∀𝑃::𝖳𝗒.𝖲𝗍𝗋𝗂𝗉𝐹𝑃→𝑃→𝐹𝑃,𝖳𝖠𝗉𝗉:=𝜆𝐹::𝖳𝗒→𝖳𝗒.∀𝑃::𝖳𝗒.𝐹𝑃→∀𝑄::𝖳𝗒.(𝑃→𝐹𝑄)→𝐹𝑄,𝖤𝗑𝗉:=𝜆𝛼::𝑈.∀𝐹::𝖳𝗒→𝖳𝗒.𝖠𝖻𝗌𝐹→𝖠𝗉𝗉𝐹→𝖳𝖠𝖻𝗌𝐹→𝖳𝖠𝗉𝗉𝐹→𝖮𝗉𝐹𝛼. The binders 𝑃,𝑄 in these case types range over represented result constructors; source types are written 𝐴,𝐵 only in the prequotation clauses of definition 7.62. The fold consumes one algebra component for each representation constructor and returns the component indexed by the represented type. In particular, an application node consumes 𝖠𝗉𝗉 𝐹, a represented function in 𝐹(𝐹𝑃 →𝐹𝑄), and a represented argument in 𝐹𝑃, producing 𝐹𝑄. For 𝖳𝖠𝖻𝗌, the case consumes the stripping operation and the stripped body 𝑃, then returns 𝐹𝑃. In a prequotation, 𝐹 and the four term variables abs,app,tabs,tapp are fixed. Transform a source context Γ =𝑥1 :𝐴1,…,𝑥𝑛 :𝐴𝑛 into Γ𝐹=𝑥1:𝐹𝗉𝗋𝖾𝐹(𝐴1),…,𝑥𝑛:𝐹𝗉𝗋𝖾𝐹(𝐴𝑛). Abbreviate the complete case-variable context by Ξ𝐹:=abs:𝖠𝖻𝗌𝐹,app:𝖠𝗉𝗉𝐹,tabs:𝖳𝖠𝖻𝗌𝐹,tapp:𝖳𝖠𝗉𝗉𝐹.
Write D ⇝𝐹𝑞 for the external, derivation-directed deep prequotation: a relation that recursively encodes the final rule and premise encodings of D. Its clauses are: 𝑥⇝𝐹𝑥,𝜆𝑥:𝐴.𝑒:𝐵⇝𝐹abs[𝗉𝗋𝖾𝐹(𝐴)][𝗉𝗋𝖾𝐹(𝐵)](𝜆𝑥:𝐹𝗉𝗋𝖾𝐹(𝐴).𝑞),𝑒1𝑒2:𝐵⇝𝐹app[𝗉𝗋𝖾𝐹(𝐴)][𝗉𝗋𝖾𝐹(𝐵)]𝑞1𝑞2,(𝑒1:𝐴→𝐵⇝𝐹𝑞1, 𝑒2:𝐴⇝𝐹𝑞2),Λ𝑢::𝜅.𝑒:𝐴⇝𝐹tabs[𝗉𝗋𝖾𝐹(∀𝑢::𝜅.𝐴)]𝗌𝗍𝗋𝗂𝗉𝐹,𝜅,𝗉𝗋𝖾𝐹(𝜆𝑢::𝜅.𝐴)(Λ𝑢::𝜅.𝑞),𝑒[𝐶]:𝐴[𝐶/𝑢]⇝𝐹tapp[𝗉𝗋𝖾𝐹(∀𝑢::𝜅.𝐴)]𝑞[𝗉𝗋𝖾𝐹(𝐴[𝐶/𝑢])]𝗂𝗇𝗌𝗍𝗉𝗋𝖾𝐹(∀𝑢::𝜅.𝐴),𝗉𝗋𝖾𝐹(𝐶). In the abstraction clause, the induction hypothesis derives 𝑞 :𝐹 𝗉𝗋𝖾𝐹(𝐵) under 𝑥 :𝐹 𝗉𝗋𝖾𝐹(𝐴) from Γ,𝑥 :𝐴 ⊢𝑒 :𝐵. In the application clause, the induction hypotheses derive 𝑞1 :𝐹 𝗉𝗋𝖾𝐹(𝐴 →𝐵) and 𝑞2 :𝐹 𝗉𝗋𝖾𝐹(𝐴). Constructor abstraction retains its binder kind; constructor application records the prequotations of its operator, argument, and result indices. Conversion changes only the derivation’s result type, so the quoted term remains 𝑞.
If D is a closed derivation of 𝑒 :𝐴, its deep quotation is ̂D:=Λ𝐹::𝖳𝗒→𝖳𝗒.𝜆abs:𝖠𝖻𝗌𝐹.𝜆app:𝖠𝗉𝗉𝐹.𝜆tabs:𝖳𝖠𝖻𝗌𝐹.𝜆tapp:𝖳𝖠𝗉𝗉𝐹.𝑞.
Referenced from 3 locations
For a source instance 𝑒[𝐶], the recursive quotation has type 𝐹𝑃, where 𝑃 represents the universal type of 𝑒. The instantiation term has type 𝑃 →𝐹𝑅, where 𝑅 represents the result type. Therefore the case must accept 𝐹𝑃, then 𝑃 →𝐹𝑅, and return 𝐹𝑅: tapp[𝑃]𝑞[𝑅]𝑔:𝐹𝑅(𝑞:𝐹𝑃, 𝑔:𝑃→𝐹𝑅). Accordingly, the 𝖳𝖠𝗉𝗉 component in (7.11) has type ∀𝑃. 𝐹𝑃 →∀𝑅. (𝑃 →𝐹𝑅) →𝐹𝑅; its quantifiers make one case term applicable at every source operator and result type.
Quote the closed instance 𝑒0:=(Λ𝑍::𝖳𝗒.𝜆𝑧:𝑍.𝑧)[𝐼]:𝐼→𝐼. For the fixed fold parameter 𝐹, abbreviate 𝑃𝐹:=𝗉𝗋𝖾𝐹(𝐼)=∀𝑍::𝖳𝗒.𝐹(𝐹𝑍→𝐹𝑍), and 𝑅𝐹:=𝗉𝗋𝖾𝐹(𝐼→𝐼)=𝐹𝑃𝐹→𝐹𝑃𝐹. The copied variable has type 𝐹𝑍. The abstraction clause therefore gives 𝑞abs:=abs[𝑍][𝑍](𝜆𝑧:𝐹𝑍.𝑧):𝐹(𝐹𝑍→𝐹𝑍). The constructor-abstraction clause wraps this family: 𝑞tabs:=tabs[𝑃𝐹]𝗌𝗍𝗋𝗂𝗉𝐹,𝖳𝗒,𝗉𝗋𝖾𝐹(𝜆𝑍::𝖳𝗒.𝑍→𝑍)(Λ𝑍::𝖳𝗒.𝑞abs):𝐹𝑃𝐹. Finally, 𝗂𝗇𝗌𝗍𝑃𝐹,𝑃𝐹 :𝑃𝐹 →𝐹𝑅𝐹, so the type-application clause is 𝑞0:=tapp[𝑃𝐹]𝑞tabs[𝑅𝐹]𝗂𝗇𝗌𝗍𝑃𝐹,𝑃𝐹:𝐹𝑅𝐹. Abstracting 𝐹 and the four case variables as in (7.12) produces ̂D0:𝖤𝗑𝗉̂(𝐼→𝐼). The term tree visibly contains one term-abstraction case, one constructor-abstraction case, and one constructor-application case; no general proof has yet been used.
Referenced from 2 locations
★★☆ Reconstruct the three displayed clauses for the quotation of (Λ𝑍 ::𝖳𝗒.𝜆𝑧 :𝑍.𝑧)[𝐼]. In particular, derive the types of 𝑞abs, 𝑞tabs, and 𝑞0 from the four case interfaces, and explain why the two constructor arguments supplied to tapp are 𝑃𝐹 and 𝑅𝐹, in that order.
Referenced from 3 locations
If D derives Δ;Γ ⊢𝑒 :𝐴 and D ⇝𝐹𝑞, then, in the context containing Γ𝐹 and the four case variables of (7.11), Δ,𝐹::𝖳𝗒→𝖳𝗒;Γ𝐹,Ξ𝐹⊢𝑞:𝐹𝗉𝗋𝖾𝐹(𝐴). For a closed derivation, ⊢̂D:𝖤𝗑𝗉̂𝐴, and ̂D is term-beta-normal.
Referenced from 3 locations
Proof of Lemma 7.64 — Fundamental typing lemma for deep quotation
Proof. Induct on D. The variable case is the definition of Γ𝐹. For term abstraction the induction hypothesis gives 𝑞 :𝐹 𝗉𝗋𝖾𝐹(𝐵) under 𝑥 :𝐹 𝗉𝗋𝖾𝐹(𝐴). Hence the copied abstraction has type 𝐹𝗉𝗋𝖾𝐹(𝐴)→𝐹𝗉𝗋𝖾𝐹(𝐵), and the abs case returns 𝐹(𝐹 𝗉𝗋𝖾𝐹(𝐴) →𝐹 𝗉𝗋𝖾𝐹(𝐵)) =𝐹 𝗉𝗋𝖾𝐹(𝐴 →𝐵). For term application, the two induction hypotheses have exactly the first two argument types required by app, which returns 𝐹 𝗉𝗋𝖾𝐹(𝐵).
For type abstraction put 𝑃:=𝗉𝗋𝖾𝐹(∀𝑢::𝜅.𝐴)=∀𝑢::𝜅.𝐹𝗉𝗋𝖾𝐹(𝐴),𝑇:=𝗉𝗋𝖾𝐹(𝜆𝑢::𝜅.𝐴). The induction hypothesis gives Λ𝑢 ::𝜅.𝑞 :𝑃, while (7.9) gives 𝗌𝗍𝗋𝗂𝗉𝐹,𝜅,𝑇 :𝖲𝗍𝗋𝗂𝗉 𝐹 (∀𝑢 ::𝜅.𝐹(𝑇𝑢)). Since 𝑇𝑢 →𝛽𝗉𝗋𝖾𝐹(𝐴), constructor conversion changes this type to 𝖲𝗍𝗋𝗂𝗉 𝐹 𝑃. Thus tabs[𝑃] returns 𝐹𝑃, as required.
For type application put 𝑃 =𝗉𝗋𝖾𝐹(∀𝑢 ::𝜅.𝐴) and 𝑅 =𝗉𝗋𝖾𝐹(𝐴[𝐶/𝑢]). The induction hypothesis gives 𝑞 :𝐹𝑃. By (7.8), 𝗂𝗇𝗌𝗍𝑃,𝗉𝗋𝖾𝐹(𝐶) has domain 𝑃 and codomain (𝐹𝗉𝗋𝖾𝐹(𝐴))[𝗉𝗋𝖾𝐹(𝐶)/𝑢]=𝐹(𝗉𝗋𝖾𝐹(𝐴)[𝗉𝗋𝖾𝐹(𝐶)/𝑢])𝑙𝑒𝑚𝑚𝑎7.61.2=𝐹𝑅. These are exactly the arguments expected by tapp[𝑃]𝑞[𝑅], so the result has type 𝐹𝑅. In the conversion case, lemma 7.61 converts the induction-hypothesis type to the required one.
For a closed derivation, abstracting the five designated variables yields ∀𝐹::𝖳𝗒→𝖳𝗒.𝖠𝖻𝗌𝐹→𝖠𝗉𝗉𝐹→𝖳𝖠𝖻𝗌𝐹→𝖳𝖠𝗉𝗉𝐹→𝐹𝗉𝗋𝖾𝐹(𝐴), which is definitionally 𝖤𝗑𝗉 ̂𝐴. Normality follows by the same induction. Every apparent application in 𝑞 has one of the four case variables at its head. The inserted 𝗂𝗇𝗌𝗍 and 𝗌𝗍𝗋𝗂𝗉 terms are themselves normal and are passed as arguments, not applied there. Copied binders preserve normality. Type-level redexes in annotations are, by our convention, not term redexes. ◻
The representation is deep: eliminating a quoted expression requires handlers for term abstraction, term application, constructor abstraction, and constructor application. Applying a quotation to those four handlers is the eliminator 𝖿𝗈𝗅𝖽𝖤𝗑𝗉:=Λ𝐹::𝖳𝗒→𝖳𝗒.𝜆𝑎:𝖠𝖻𝗌𝐹.𝜆𝑝:𝖠𝗉𝗉𝐹.𝜆𝑡𝑎:𝖳𝖠𝖻𝗌𝐹.𝜆𝑡𝑝:𝖳𝖠𝗉𝗉𝐹.Λ𝛼::𝑈.𝜆𝑟:𝖤𝗑𝗉𝛼.𝑟[𝐹]𝑎𝑝𝑡𝑎𝑡𝑝 of type ∀𝐹::𝖳𝗒→𝖳𝗒.𝖠𝖻𝗌𝐹→𝖠𝗉𝗉𝐹→𝖳𝖠𝖻𝗌𝐹→𝖳𝖠𝗉𝗉𝐹→∀𝛼::𝑈.𝖤𝗑𝗉𝛼→𝖮𝗉𝐹𝛼.
If D is closed and D ⇝𝐹𝑞, then applying 𝖿𝗈𝗅𝖽𝖤𝗑𝗉 to a constructor 𝐺, four case terms, ̂𝐴, and ̂D reduces to 𝑞 with 𝐹 and the four designated case variables simultaneously replaced by those arguments.
Referenced from 3 locations
Proof of Lemma 7.65 — Fold calculation
Proof. Writing the four case arguments as 𝑎,𝑝,𝑡𝑎,𝑡𝑝, expansion gives the complete head calculation 𝖿𝗈𝗅𝖽𝖤𝗑𝗉[𝐺]𝑎𝑝𝑡𝑎𝑡𝑝[̂𝐴]̂D𝑢𝑛𝑓𝑜𝑙𝑑𝖿𝗈𝗅𝖽𝖤𝗑𝗉⟶∗𝛽̂D[𝐺]𝑎𝑝𝑡𝑎𝑡𝑝𝑢𝑛𝑓𝑜𝑙𝑑̂D⟶∗𝛽𝑞[𝐺/𝐹,𝑎/abs,𝑝/app,𝑡𝑎/tabs,𝑡𝑝/tapp]. No induction is needed: this is the beta law of the Church encoding, in the sense explained for Church naturals in definition 5.18. ◻
The internal unquoter
Take the identity type operator 𝖨𝖽:=𝜆𝐴::𝖳𝗒.𝐴 and the following four cases: 𝗎𝗇𝖠𝖻𝗌:=Λ𝐴::𝖳𝗒.Λ𝐵::𝖳𝗒.𝜆𝑓:𝐴→𝐵.𝑓,𝗎𝗇𝖠𝗉𝗉:=Λ𝐴::𝖳𝗒.Λ𝐵::𝖳𝗒.𝜆𝑓:𝐴→𝐵.𝜆𝑥:𝐴.𝑓𝑥,𝗎𝗇𝖳𝖠𝖻𝗌:=Λ𝐴::𝖳𝗒.𝜆𝑠:𝖲𝗍𝗋𝗂𝗉𝖨𝖽𝐴.𝜆𝑓:𝐴.𝑓,𝗎𝗇𝖳𝖠𝗉𝗉:=Λ𝐴::𝖳𝗒.𝜆𝑓:𝐴.Λ𝐵::𝖳𝗒.𝜆𝑔:𝐴→𝐵.𝑔𝑓. They have types 𝖠𝖻𝗌 𝖨𝖽, 𝖠𝗉𝗉 𝖨𝖽, 𝖳𝖠𝖻𝗌 𝖨𝖽, and 𝖳𝖠𝗉𝗉 𝖨𝖽 respectively. Define the ordinary internal 𝐹𝜔 term 𝗎𝗇𝗊𝗎𝗈𝗍𝖾:=𝖿𝗈𝗅𝖽𝖤𝗑𝗉[𝖨𝖽]𝗎𝗇𝖠𝖻𝗌𝗎𝗇𝖠𝗉𝗉𝗎𝗇𝖳𝖠𝖻𝗌𝗎𝗇𝖳𝖠𝗉𝗉,𝗎𝗇𝗊𝗎𝗈𝗍𝖾:∀𝛼::𝑈.𝖤𝗑𝗉𝛼→𝖮𝗉𝖨𝖽𝛼.
For every well-kinded constructor 𝐴, 𝗉𝗋𝖾𝐹(𝐴)[𝖨𝖽/𝐹]→∗𝛽𝐴. If 𝐴 is a closed type, then 𝖮𝗉 𝖨𝖽 ̂𝐴 =𝛽𝐴.
Referenced from 6 locations
Proof of Lemma 7.66 — Recovery of represented types
Proof. Induct on 𝐴. A variable is unchanged. For an arrow, the induction hypotheses and the two contractions 𝖨𝖽 𝑋 →𝛽𝑋 give 𝖨𝖽𝗉𝗋𝖾𝖨𝖽(𝐴)→∗𝛽𝐴,𝖨𝖽𝗉𝗋𝖾𝖨𝖽(𝐵)→∗𝛽𝐵. For a universal, contract its one occurrence of 𝖨𝖽 and reduce under the binder. Constructor abstraction reduces under its binder, and constructor application uses the two induction hypotheses in its operator and argument positions. Hence the variable, arrow, universal, constructor- abstraction, and constructor-application clauses all reduce to their original types under 𝖨𝖽.
Finally, 𝖮𝗉𝖨𝖽̂𝐴𝑢𝑛𝑓𝑜𝑙𝑑𝖮𝗉→∗𝛽𝖨𝖽(̂𝐴𝖨𝖽)𝑢𝑛𝑓𝑜𝑙𝑑̂𝐴→∗𝛽𝗉𝗋𝖾𝖨𝖽(𝐴)𝑖𝑛𝑑𝑢𝑐𝑡𝑖𝑜𝑛ℎ𝑦𝑝𝑜𝑡ℎ𝑒𝑠𝑖𝑠→∗𝛽𝐴. ◻
Let D ⇝𝐹𝑞. Substitute 𝖨𝖽 for 𝐹 and the four terms in (7.14) for the four case variables. The resulting term reduces by ⟹∗𝛽 to the source term of D. By term-only reduction it reaches a term ≈ty-equivalent to that source.
Referenced from 4 locations
Proof of Lemma 7.67 — Unquoting a prequotation
Proof. Induct on D. A variable is unchanged. In the term-abstraction case, the 𝗎𝗇𝖠𝖻𝗌 case contracts to the copied abstraction, and the induction hypothesis reduces its body: 𝗎𝗇𝖠𝖻𝗌[𝗉𝗋𝖾𝖨𝖽(𝐴)][𝗉𝗋𝖾𝖨𝖽(𝐵)](𝜆𝑥:𝖨𝖽𝗉𝗋𝖾𝖨𝖽(𝐴).𝑞′)𝑢𝑛𝑓𝑜𝑙𝑑𝗎𝗇𝖠𝖻𝗌,𝑡ℎ𝑒𝑛𝑏𝑒𝑡𝑎⟹∗𝛽𝜆𝑥:𝐴.𝑒. By lemma 7.66, 𝖨𝖽𝗉𝗋𝖾𝖨𝖽(𝐴) →∗𝛽𝐴 and 𝖨𝖽𝗉𝗋𝖾𝖨𝖽(𝐵) →∗𝛽𝐵, so constructor conversion validates the annotations in this calculation. In term application, 𝗎𝗇𝖠𝗉𝗉 applies the two induction-hypothesis results and hence reduces to 𝑒1𝑒2.
In type abstraction, 𝗎𝗇𝖳𝖠𝖻𝗌 ignores its strip argument and returns the copied type abstraction; compatible reduction and the induction hypothesis give Λ𝑢 ::𝜅.𝑒.
For type application, write 𝑃 =𝗉𝗋𝖾𝖨𝖽(∀𝑢 ::𝜅.𝐴) and 𝑄 =𝗉𝗋𝖾𝖨𝖽(𝐶). The decisive contractions are 𝗎𝗇𝖳𝖠𝗉𝗉[𝑃]𝑞′[𝗉𝗋𝖾𝖨𝖽(𝐴[𝐶/𝑢])]𝗂𝗇𝗌𝗍𝑃,𝑄⟹∗𝛽𝗂𝗇𝗌𝗍𝑃,𝑄𝑞′(7.8)⟹𝛽𝑞′[𝑄]𝐼𝐻𝑎𝑛𝑑𝑡𝑦𝑝𝑒𝑟𝑒𝑐𝑜𝑣𝑒𝑟𝑦⟹∗𝛽𝑒[𝐶]. If the last rule of D is conversion from 𝐴 to 𝐵, the induction hypothesis unquotes the unchanged term 𝑞 at 𝐴, and constructor conversion assigns the same term type 𝐵. The variable, abstraction, application, constructor-abstraction, constructor-application, and conversion cases exhaust the derivation rules. ◻
If D is a closed derivation of 𝑒 :𝐴 in the pure 𝐹𝜔 signature of lemma 7.56, then 𝗎𝗇𝗊𝗎𝗈𝗍𝖾[̂𝐴]̂D⟹∗𝛽𝑒,⊢𝗎𝗇𝗊𝗎𝗈𝗍𝖾[̂𝐴]̂D:𝐴.
Referenced from 5 locations
Proof of Theorem 7.68 — Strong typed self-interpretation
Proof. The typing judgment follows from lemma 7.64, lemma 7.66 and the type of (7.15). By lemma 7.65, the term reduces to the prequotation with 𝐹 and the four cases replaced by the unquoting choices. By lemma 7.67, that term reduces to 𝑒. ◻
★★☆ Work the constructor-application case of lemma 7.67 without abbreviating the 𝗎𝗇𝖳𝖠𝗉𝗉 and 𝗂𝗇𝗌𝗍 redexes. Starting from the prequotation of 𝑒[𝐶], display every term-beta contraction that exposes the recursive quotation of 𝑒 instantiated at the represented constructor 𝐶. Mark the two places where lemma 7.66 supplies constructor conversion.
Referenced from 3 locations
The shallow and deep representations, their internal unquoters, and the fold interface follow Brown and Palsberg [BP16]; the typing and reduction obligations used here are stated and proved locally.
Let D1 and D2 be closed derivations of 𝑒1 :𝐴 and 𝑒2 :𝐴. If ̂D1 ≡mix𝛽̂D2, then 𝑒1 ≡mix𝛽𝑒2.
Referenced from 2 locations
Proof of Corollary 7.69 — Separation of represented beta classes
Proof. Mixed beta equivalence is a congruence, so apply the same internal term 𝗎𝗇𝗊𝗎𝗈𝗍𝖾[̂𝐴] to both quotations. The two results remain equivalent. By theorem 7.68, they reduce respectively to 𝑒1 and 𝑒2. ◻
There is a genuine self-application calculation, but it contains a quotation, not the forbidden raw diagonal application. Let 𝑇𝑢:=∀𝛼::𝑈.𝖤𝗑𝗉𝛼→𝖮𝗉𝖨𝖽𝛼 be the type of 𝗎𝗇𝗊𝗎𝗈𝗍𝖾, and let D𝑢 be its closed typing derivation. Applying the theorem to that derivation gives 𝗎𝗇𝗊𝗎𝗈𝗍𝖾[̂𝑇𝑢]̂D𝑢⟹∗𝛽𝗎𝗇𝗊𝗎𝗈𝗍𝖾. Quotation remains a meta-level operation. Equation (7.16) therefore constructs no internal term of type 𝐴 →𝖤𝗑𝗉 ̂𝐴 and does not contradict the normalization barrier of proposition 7.57. Every term in this calculation is an ordinary well-typed term of pure 𝐹𝜔; adding no term former or reduction rule means that the strong normalization and syntactic-consistency results for that calculus remain unchanged.
Recognizing the outer constructor
Use the Church booleans 𝖡𝗈𝗈𝗅:=∀𝑋::𝖳𝗒.𝑋→𝑋→𝑋,𝗍𝗋𝗎𝖾:=Λ𝑋::𝖳𝗒.𝜆𝑡:𝑋.𝜆𝑓:𝑋.𝑡,𝖿𝖺𝗅𝗌𝖾:=Λ𝑋::𝖳𝗒.𝜆𝑡:𝑋.𝜆𝑓:𝑋.𝑓,𝐾𝖡𝗈𝗈𝗅:=𝜆𝐴::𝖳𝗒.𝖡𝗈𝗈𝗅. The four cases need not inspect their recursive arguments: 𝗂𝗌𝖠𝖻𝗌𝖠𝖻𝗌:=Λ𝐴.Λ𝐵.𝜆𝑓:𝖡𝗈𝗈𝗅→𝖡𝗈𝗈𝗅.𝗍𝗋𝗎𝖾,𝗂𝗌𝖠𝖻𝗌𝖠𝗉𝗉:=Λ𝐴.Λ𝐵.𝜆𝑓:𝖡𝗈𝗈𝗅.𝜆𝑥:𝖡𝗈𝗈𝗅.𝖿𝖺𝗅𝗌𝖾,𝗂𝗌𝖠𝖻𝗌𝖳𝖠𝖻𝗌:=Λ𝐴.𝜆𝑠:𝖲𝗍𝗋𝗂𝗉𝐾𝖡𝗈𝗈𝗅𝐴.𝜆𝑓:𝐴.𝗍𝗋𝗎𝖾,𝗂𝗌𝖠𝖻𝗌𝖳𝖠𝗉𝗉:=Λ𝐴.𝜆𝑓:𝖡𝗈𝗈𝗅.Λ𝐵.𝜆𝑔:𝐴→𝖡𝗈𝗈𝗅.𝖿𝖺𝗅𝗌𝖾. Every constructor binder without an explicit kind in (7.17) has kind 𝖳𝗒. The four terms have the four case types at 𝐾𝖡𝗈𝗈𝗅. Since 𝖮𝗉 𝐾𝖡𝗈𝗈𝗅 𝛼 =𝛽𝖡𝗈𝗈𝗅, define 𝗂𝗌𝖠𝖻𝗌:=𝖿𝗈𝗅𝖽𝖤𝗑𝗉[𝐾𝖡𝗈𝗈𝗅]𝗂𝗌𝖠𝖻𝗌𝖠𝖻𝗌𝗂𝗌𝖠𝖻𝗌𝖠𝗉𝗉𝗂𝗌𝖠𝖻𝗌𝖳𝖠𝖻𝗌𝗂𝗌𝖠𝖻𝗌𝖳𝖠𝗉𝗉,𝗂𝗌𝖠𝖻𝗌:∀𝛼::𝑈.𝖤𝗑𝗉𝛼→𝖡𝗈𝗈𝗅.
Let D be a closed derivation of 𝑒 :𝐴. If 𝑒 is a term abstraction or a type abstraction, then 𝗂𝗌𝖠𝖻𝗌[̂𝐴]̂D⟶∗𝛽𝗍𝗋𝗎𝖾. If 𝑒 is a term application or a type application, the same expression reduces to 𝖿𝖺𝗅𝗌𝖾.
Referenced from 3 locations
Proof of Theorem 7.70 — Correctness of the abstraction test
Proof. The fold calculation exposes the outermost prequotation clause. In the two abstraction clauses, the corresponding case in (7.17) discards its recursive argument and returns 𝗍𝗋𝗎𝖾. In the two application clauses it returns 𝖿𝖺𝗅𝗌𝖾. A closed term cannot have a free variable at its root, and conversion adds no term constructor. These exhaust the possibilities. ◻
Counting term nodes
Define Church natural numbers inside pure 𝐹𝜔 by 𝖭𝖺𝗍:=∀𝑋::𝖳𝗒.𝑋→(𝑋→𝑋)→𝑋,𝗓𝖾𝗋𝗈:=Λ𝑋.𝜆𝑧:𝑋.𝜆𝑠:𝑋→𝑋.𝑧,𝗌𝗎𝖼𝖼:=𝜆𝑛:𝖭𝖺𝗍.Λ𝑋.𝜆𝑧:𝑋.𝜆𝑠:𝑋→𝑋.𝑠(𝑛[𝑋]𝑧𝑠),𝗉𝗅𝗎𝗌:=𝜆𝑚:𝖭𝖺𝗍.𝜆𝑛:𝖭𝖺𝗍.𝑚[𝖭𝖺𝗍]𝑛𝗌𝗎𝖼𝖼,𝗈𝗇𝖾:=𝗌𝗎𝖼𝖼𝗓𝖾𝗋𝗈,𝐾𝖭𝖺𝗍:=𝜆𝐴.𝖭𝖺𝗍. Let 𝑛―― denote the Church numeral obtained by applying 𝗌𝗎𝖼𝖼 𝑛 times to 𝗓𝖾𝗋𝗈. Then 𝗌𝗎𝖼𝖼𝑛――⟶∗𝛽𝑛+1――――,𝗉𝗅𝗎𝗌𝑚――𝑛――⟶∗𝛽𝑚+𝑛――――. The successor equation is definitional; direct beta calculation gives the addition equation.
The size of a term counts term nodes and does not count constructors in an annotation or type argument: |𝑥|=1,|𝜆𝑥:𝐴.𝑒|=1+|𝑒|,|𝑒1𝑒2|=1+|𝑒1|+|𝑒2|,|Λ𝑢::𝜅.𝑒|=1+|𝑒|,|𝑒[𝐶]|=1+|𝑒|. The cases implementing these five equations are 𝗌𝗂𝗓𝖾𝖠𝖻𝗌:=Λ𝐴.Λ𝐵.𝜆𝑓:𝖭𝖺𝗍→𝖭𝖺𝗍.𝗌𝗎𝖼𝖼(𝑓𝗈𝗇𝖾),𝗌𝗂𝗓𝖾𝖠𝗉𝗉:=Λ𝐴.Λ𝐵.𝜆𝑚:𝖭𝖺𝗍.𝜆𝑛:𝖭𝖺𝗍.𝗌𝗎𝖼𝖼(𝗉𝗅𝗎𝗌𝑚𝑛),𝗌𝗂𝗓𝖾𝖳𝖠𝖻𝗌:=Λ𝐴.𝜆𝑠:𝖲𝗍𝗋𝗂𝗉𝐾𝖭𝖺𝗍𝐴.𝜆𝑓:𝐴.𝗌𝗎𝖼𝖼(𝑠[𝖭𝖺𝗍](Λ𝐶.𝜆𝑛:𝖭𝖺𝗍.𝑛)𝑓),𝗌𝗂𝗓𝖾𝖳𝖠𝗉𝗉:=Λ𝐴.𝜆𝑚:𝖭𝖺𝗍.Λ𝐵.𝜆𝑔:𝐴→𝖭𝖺𝗍.𝗌𝗎𝖼𝖼𝑚. Their types are the four case types at 𝐾𝖭𝖺𝗍. Therefore 𝗌𝗂𝗓𝖾:=𝖿𝗈𝗅𝖽𝖤𝗑𝗉[𝐾𝖭𝖺𝗍]𝗌𝗂𝗓𝖾𝖠𝖻𝗌𝗌𝗂𝗓𝖾𝖠𝗉𝗉𝗌𝗂𝗓𝖾𝖳𝖠𝖻𝗌𝗌𝗂𝗓𝖾𝖳𝖠𝗉𝗉,𝗌𝗂𝗓𝖾:∀𝛼::𝑈.𝖤𝗑𝗉𝛼→𝖭𝖺𝗍.
If D is a closed derivation of 𝑒 :𝐴, then 𝗌𝗂𝗓𝖾[̂𝐴]̂D⟶∗𝛽|𝑒|――.
Referenced from 3 locations
Proof of Theorem 7.71 — Correctness of size
Proof. The induction must be slightly stronger than the closed statement, because a term abstraction exposes a variable in its body. Let D ⇝𝐹𝑞 be an open prequotation. For every kind-respecting closing constructor substitution 𝜃 for the open constructor context, first apply 𝜃 to 𝑞. After substituting 𝐾𝖭𝖺𝗍 and the four size cases, also substitute 𝗈𝗇𝖾 for every free term variable. We prove that the result reduces to |𝑒|――. Constructor substitution changes annotations and type arguments but not the term-constructor count.
For a variable, the extra substitution gives 𝗈𝗇𝖾 =1―― =|𝑥|――. For term abstraction, the case term calculates 𝗌𝗂𝗓𝖾𝖠𝖻𝗌[⋯](𝜆𝑥:𝖭𝖺𝗍.𝑞′)⟶∗𝛽𝗌𝗎𝖼𝖼(𝑞′[𝗈𝗇𝖾/𝑥]). The induction hypothesis gives 𝑞′[𝗈𝗇𝖾/𝑥] ⟶∗𝛽|𝑒|――, so (7.18) gives 1+|𝑒|――――. Term application gives 𝗌𝗎𝖼𝖼(𝗉𝗅𝗎𝗌|𝑒1|―――|𝑒2|―――)⟶∗𝛽1+|𝑒1|+|𝑒2|―――――――.
In type abstraction, the recursive value is Λ𝑢 ::𝜅.𝑞′. Calculation (7.10), with 𝑋 =𝖭𝖺𝗍, reduces the stripping expression to 𝑞′[𝑆𝜅/𝑢]. Apply the body induction hypothesis to the closing substitution 𝜃[𝑢 ↦𝑆𝜅]. It is kind respecting because ⊢𝑆𝜅 ::𝜅, and it gives the required size of 𝑞′[𝑆𝜅/𝑢]. Thus term size ignores the substituted type and remains |𝑒|. The outer successor therefore gives 1+|𝑒|――――. In type application, 𝗌𝗂𝗓𝖾𝖳𝖠𝗉𝗉 ignores the instantiation function and returns the successor of the operator size, namely 1+|𝑒|――――. Conversion changes neither prequotation nor size. This proves the strengthened assertion in every case. With an empty term context, the fold calculation yields the theorem. ◻
Testing beta-normality
A Boolean does not carry enough information through an application. To decide whether 𝑒1𝑒2 is normal, one must know not only that 𝑒1 is normal, but also that it is neutral and therefore cannot become a lambda redex at the root. We carry two booleans.
Define 𝖺𝗇𝖽:=𝜆𝑏1:𝖡𝗈𝗈𝗅.𝜆𝑏2:𝖡𝗈𝗈𝗅.Λ𝑋.𝜆𝑡:𝑋.𝜆𝑓:𝑋.𝑏1[𝑋](𝑏2[𝑋]𝑡𝑓)𝑓,𝖡𝗈𝗈𝗅𝗌:=∀𝑋::𝖳𝗒.(𝖡𝗈𝗈𝗅→𝖡𝗈𝗈𝗅→𝑋)→𝑋,𝖻𝗈𝗈𝗅𝗌:=𝜆𝑏:𝖡𝗈𝗈𝗅.𝜆𝑛:𝖡𝗈𝗈𝗅.Λ𝑋.𝜆𝑘:𝖡𝗈𝗈𝗅→𝖡𝗈𝗈𝗅→𝑋.𝑘𝑏𝑛,𝖿𝗌𝗍:=𝜆𝑝:𝖡𝗈𝗈𝗅𝗌.𝑝[𝖡𝗈𝗈𝗅](𝜆𝑏:𝖡𝗈𝗈𝗅.𝜆𝑛:𝖡𝗈𝗈𝗅.𝑏),𝗌𝗇𝖽:=𝜆𝑝:𝖡𝗈𝗈𝗅𝗌.𝑝[𝖡𝗈𝗈𝗅](𝜆𝑏:𝖡𝗈𝗈𝗅.𝜆𝑛:𝖡𝗈𝗈𝗅.𝑛),𝐾𝖡𝗈𝗈𝗅𝗌:=𝜆𝐴.𝖡𝗈𝗈𝗅𝗌. Define the three pairs 𝖳𝖳:=𝖻𝗈𝗈𝗅𝗌𝗍𝗋𝗎𝖾𝗍𝗋𝗎𝖾,𝖳𝖥:=𝖻𝗈𝗈𝗅𝗌𝗍𝗋𝗎𝖾𝖿𝖺𝗅𝗌𝖾,𝖥𝖥:=𝖻𝗈𝗈𝗅𝗌𝖿𝖺𝗅𝗌𝖾𝖿𝖺𝗅𝗌𝖾.
The neutral terms 𝑛 are variables and their iterated eliminations; the beta-normal terms 𝑣 are neutral terms or abstractions. They are described mutually by 𝑛::=𝑥∣𝑛𝑣∣𝑛[𝐶],𝑣::=𝑛∣𝜆𝑥:𝐴.𝑣∣Λ𝑢::𝜅.𝑣. Thus every neutral term is normal. A normal term which is not neutral is an abstraction. These grammars speak only about term redexes; a constructor 𝐶 need not be constructor-normal.
Referenced from 2 locations
For a well-typed application this grammar yields the two exact tests 𝑒1𝑒2 is normal⟺𝑒1 is normal and neutral, and 𝑒2 is normal,𝑒[𝐶] is normal⟺𝑒 is normal and neutral.
Referenced from 2 locations
Proof of Lemma 17.19 — Normal applications have neutral operators
Proof. For completeness, if a normal operator is not neutral, the grammar says it is a term abstraction or a type abstraction. Typing rules out the wrong one: a type abstraction has universal type, not arrow type, and a term abstraction has arrow type, not universal type. A final conversion cannot identify these heads, because constructor normalization gives distinct normal-form heads for → and ∀. Hence an arrow-typed nonneutral normal operator is a term abstraction, producing a term beta-redex, and a universal-typed one is a type abstraction, producing a type-application redex. This proves both directions of (7.20). ◻
Now define the four cases: 𝗇𝖿𝖠𝖻𝗌:=Λ𝐴.Λ𝐵.𝜆𝑓:𝖡𝗈𝗈𝗅𝗌→𝖡𝗈𝗈𝗅𝗌.𝖻𝗈𝗈𝗅𝗌(𝖿𝗌𝗍(𝑓𝖳𝖳))𝖿𝖺𝗅𝗌𝖾,𝗇𝖿𝖠𝗉𝗉:=Λ𝐴.Λ𝐵.𝜆𝑝:𝖡𝗈𝗈𝗅𝗌.𝜆𝑞:𝖡𝗈𝗈𝗅𝗌.𝖻𝗈𝗈𝗅𝗌(𝖺𝗇𝖽(𝗌𝗇𝖽𝑝)(𝖿𝗌𝗍𝑞))(𝖺𝗇𝖽(𝗌𝗇𝖽𝑝)(𝖿𝗌𝗍𝑞)),𝗇𝖿𝖳𝖠𝖻𝗌:=Λ𝐴.𝜆𝑠:𝖲𝗍𝗋𝗂𝗉𝐾𝖡𝗈𝗈𝗅𝗌𝐴.𝜆𝑓:𝐴.𝖻𝗈𝗈𝗅𝗌(𝖿𝗌𝗍(𝑠[𝖡𝗈𝗈𝗅𝗌](Λ𝐶.𝜆𝑝:𝖡𝗈𝗈𝗅𝗌.𝑝)𝑓))𝖿𝖺𝗅𝗌𝖾,𝗇𝖿𝖳𝖠𝗉𝗉:=Λ𝐴.𝜆𝑝:𝖡𝗈𝗈𝗅𝗌.Λ𝐵.𝜆𝑔:𝐴→𝖡𝗈𝗈𝗅𝗌.𝖻𝗈𝗈𝗅𝗌(𝗌𝗇𝖽𝑝)(𝗌𝗇𝖽𝑝). They inhabit the four case types at 𝐾𝖡𝗈𝗈𝗅𝗌. The public test returns the first component: 𝗂𝗌𝖭𝗈𝗋𝗆𝖺𝗅:=Λ𝛼::𝑈.𝜆𝑟:𝖤𝗑𝗉𝛼.𝖿𝗌𝗍(𝖿𝗈𝗅𝖽𝖤𝗑𝗉[𝐾𝖡𝗈𝗈𝗅𝗌]𝗇𝖿𝖠𝖻𝗌𝗇𝖿𝖠𝗉𝗉𝗇𝖿𝖳𝖠𝖻𝗌𝗇𝖿𝖳𝖠𝗉𝗉[𝛼]𝑟) with type ∀𝛼 ::𝑈.𝖤𝗑𝗉 𝛼 →𝖡𝗈𝗈𝗅.
Let D ⇝𝐹𝑞 be an open prequotation. For every kind-respecting closing constructor substitution 𝜃 for the open constructor context, first apply 𝜃 to 𝑞. Then substitute 𝐾𝖡𝗈𝗈𝗅𝗌, the four cases in (7.21), and 𝖳𝖳 for each free term variable. The resulting closed term reduces by ⟹∗𝛽 to the pair in the second column of the following table: state of the source term 𝑒result𝑒 normal and neutral𝖳𝖳𝑒 normal and not neutral𝖳𝖥𝑒 not normal𝖥𝖥.
Referenced from 3 locations
Proof of Lemma 7.73 — The three-state invariant
Proof. Induct on the source typing derivation. A variable is replaced by 𝖳𝖳, as required.
For a term abstraction, 𝗇𝖿𝖠𝖻𝗌 applies the recursive function to 𝖳𝖳, exactly the value assigned to the newly bound variable. By the induction hypothesis the first projection is true precisely when the body is normal. The second result component is false. The result is therefore 𝖳𝖥 for a normal abstraction and 𝖥𝖥 for a nonnormal one.
For term application, let 𝑝 and 𝑞 be the two recursive result pairs. The case puts the same Boolean (𝗌𝗇𝖽𝑝)𝖺𝗇𝖽(𝖿𝗌𝗍𝑞) in both components. By the induction hypotheses this Boolean is true exactly when the operator is normal and neutral and the operand is normal. By (7.20), this is exactly when the whole application is normal; in that event the application is neutral. Thus the result is 𝖳𝖳 in the normal case and 𝖥𝖥 otherwise.
For type abstraction, the stripping calculation (7.10) with 𝑋 =𝖡𝗈𝗈𝗅𝗌 selects the body at 𝑆𝜅. Apply the body induction hypothesis to the closing substitution 𝜃[𝑢 ↦𝑆𝜅], which is kind respecting because ⊢𝑆𝜅 ::𝜅. The case copies its first component and sets the second to false, giving 𝖳𝖥 exactly when the body, and hence the abstraction, is normal; otherwise it gives 𝖥𝖥.
For type application, the case copies the operator’s second component into both result positions. It therefore returns 𝖳𝖳 exactly when the operator is normal and neutral, and 𝖥𝖥 otherwise. This is exactly the second equivalence of (7.20); a normal type application is itself neutral. Conversion changes no term and hence no state. The application equation in (7.20) holds exactly when the operator is neutral-normal and the operand is normal. ◻
For a closed derivation D of 𝑒 :𝐴, 𝗂𝗌𝖭𝗈𝗋𝗆𝖺𝗅[̂𝐴]̂D⟶∗𝛽{𝗍𝗋𝗎𝖾,𝑒 is beta-normal,𝖿𝖺𝗅𝗌𝖾,𝑒 is not beta-normal.
Referenced from 3 locations
Proof of Theorem 7.74 — Correctness of the normal-form test
Proof. By the fold calculation and lemma 7.73, the intermediate pair is 𝖳𝖳 or 𝖳𝖥 precisely when 𝑒 is normal, and is 𝖥𝖥 otherwise. Its first projection is respectively 𝗍𝗋𝗎𝖾 or 𝖿𝖺𝗅𝗌𝖾. ◻
★☆☆ Let 𝑒 =(Λ𝐴 ::𝖳𝗒.𝜆𝑥 :𝐴.𝑥)[∀𝑋 ::𝖳𝗒.𝑋 →𝑋]. Determine |𝑒|, decide whether 𝑒 is normal, and compute the results of 𝗂𝗌𝖠𝖻𝗌, 𝗌𝗂𝗓𝖾, and 𝗂𝗌𝖭𝗈𝗋𝗆𝖺𝗅 on its deep quotation. In the normality calculation, name the three-state pair obtained for the operator before the final type-application case is used.
Referenced from 3 locations
Typed CPS consumers
Continuation-passing style (CPS) replaces a computation returning 𝐴 by a computation that receives a continuation 𝐴 →𝐵 and sends its result to that continuation. The common answer operator and result family for the call-by-name and call-by-value folds are 𝖢𝗍:=𝜆𝐴::𝖳𝗒.∀𝐵::𝖳𝗒.(𝐴→𝐵)→𝐵,𝖢𝖯𝖲:=𝖮𝗉𝖢𝗍. The call-by-name case operators are the following pure 𝐹𝜔 terms: 𝖼𝗉𝗌𝖠𝖻𝗌n:=Λ𝐴.Λ𝐵.𝜆𝑓:𝖢𝗍𝐴→𝖢𝗍𝐵.Λ𝑉.𝜆𝑘:(𝖢𝗍𝐴→𝖢𝗍𝐵)→𝑉.𝑘𝑓,𝖼𝗉𝗌𝖠𝗉𝗉n:=Λ𝐴.Λ𝐵.𝜆𝑓:𝖢𝗍(𝖢𝗍𝐴→𝖢𝗍𝐵).𝜆𝑥:𝖢𝗍𝐴.Λ𝑉.𝜆𝑘:𝐵→𝑉.𝑓[𝑉](𝜆𝑔:𝖢𝗍𝐴→𝖢𝗍𝐵.𝑔𝑥[𝑉]𝑘),𝖼𝗉𝗌𝖳𝖠𝖻𝗌n:=Λ𝐴.𝜆𝑠:𝖲𝗍𝗋𝗂𝗉𝖢𝗍𝐴.𝜆𝑓:𝐴.Λ𝑉.𝜆𝑘:𝐴→𝑉.𝑘𝑓,𝖼𝗉𝗌𝖳𝖠𝗉𝗉n:=Λ𝐴.𝜆𝑓:𝖢𝗍𝐴.Λ𝐵.𝜆𝑔:𝐴→𝖢𝗍𝐵.Λ𝑉.𝜆𝑘:𝐵→𝑉.𝑓[𝑉](𝜆𝑥:𝐴.𝑔𝑥[𝑉]𝑘). They have the four case types at 𝖢𝗍, so their fold has type 𝖼𝗉𝗌n:∀𝛼::𝑈.𝖤𝗑𝗉𝛼→𝖢𝖯𝖲𝛼. The call-by-name abstraction case performs the continuation transfer. For 𝑓 :𝖢𝗍 𝐴 →𝖢𝗍 𝐵 and 𝑘 :(𝖢𝗍 𝐴 →𝖢𝗍 𝐵) →𝑉, 𝖼𝗉𝗌𝖠𝖻𝗌n[𝐴][𝐵]𝑓[𝑉]𝑘𝑡𝑦𝑝𝑒𝑏𝑒𝑡𝑎𝑎𝑛𝑑𝑡𝑒𝑟𝑚𝑏𝑒𝑡𝑎⟶∗𝛽𝑘𝑓. The application 𝑘 𝑓 has type 𝑉, the codomain of the continuation. Thus this calculation proves the declared case typing; it does not assert an operational simulation of source evaluation. The call-by-value artifact uses the same three application and type cases. It replaces the abstraction case by 𝖼𝗉𝗌𝖠𝖻𝗌v:=Λ𝐴.Λ𝐵.𝜆𝑓:𝖢𝗍𝐴→𝖢𝗍𝐵.Λ𝑉.𝜆𝑘:(𝖢𝗍𝐴→𝖢𝗍𝐵)→𝑉.𝑘(𝜆𝑥:𝖢𝗍𝐴.𝑥[𝖢𝗍𝐵](𝜆𝑎:𝐴.𝑓(Λ𝑊.𝜆ℎ:𝐴→𝑊.ℎ𝑎))), and its fold has the same public type ∀𝛼 ::𝑈.𝖤𝗑𝗉 𝛼 →𝖢𝖯𝖲 𝛼.
Construction boundaries
For every derivation D of 𝑒 :𝐴, the external map constructs ̂D :𝖤𝗑𝗉 ̂𝐴. The internal term 𝗎𝗇𝗊𝗎𝗈𝗍𝖾:∀𝛼::𝑈.𝖤𝗑𝗉𝛼→𝖮𝗉𝖨𝖽𝛼 sends this representation back to a term of 𝐴. Each CPS fold instead has type ∀𝛼 ::𝑈.𝖤𝗑𝗉 𝛼 →𝖢𝖯𝖲 𝛼 for its fixed continuation operator. The first map is derivation-directed; the latter two are 𝐹𝜔 terms. These types neither make every inhabitant of 𝖤𝗑𝗉 ̂𝐴 a quotation nor assert that the CPS term simulates source evaluation.
The classical diagonal obstruction also still applies internally at the numeric interface. There is no closed 𝑉 :𝖭𝖺𝗍 →𝖭𝖺𝗍 →𝖭𝖺𝗍 such that every closed 𝑓 :𝖭𝖺𝗍 →𝖭𝖺𝗍 has a numeral 𝑎―― with 𝑉 𝑎―― 𝑛―― =𝛽𝑓 𝑛―― for every 𝑛. Otherwise 𝑑:=𝜆𝑛.𝗌𝗎𝖼𝖼(𝑉 𝑛 𝑛) would have an index 𝑎――, and the instance at 𝑎―― would equate a Church numeral with its successor. Strong normalization and confluence distinguish those normal forms. Typed self-representation evades the raw diagonal only through its type index; it does not enumerate all total numeric functions.
The failure of surjectivity is already visible in the shallow construction. The closed term 𝗃𝗎𝗇𝗄sh:=𝜆𝑖:𝐼.𝑖:𝐼→𝐼 is not the shallow quotation of any closed derivation of a term of type 𝐼. Indeed, such a quotation has the form 𝜆𝑖 :𝐼.𝑞. If the source ends in an abstraction, then 𝑞 begins with the copied abstraction. If it ends in an application, then 𝑞 is headed by 𝑖 applied to at least one type and one term argument. A closed source cannot end in a variable, and conversion does not change 𝑞. A source constructor abstraction makes 𝑞 begin with the copied constructor abstraction; a source constructor application makes 𝑞 headed by 𝑖 applied to a constructor argument. None gives the bare body 𝑖. Both 𝗃𝗎𝗇𝗄sh and every shallow quotation are normal, so confluence also rules out beta-equivalence between them.
Referenced from 2 locations
Fix a closed type 𝐵. For each fold parameter 𝐹, abbreviate 𝐴𝐹:=𝗉𝗋𝖾𝐹(𝐵),𝑃𝐹:=𝐹𝐴𝐹→𝐹𝐴𝐹,𝑞𝐹:=abs[𝐴𝐹][𝐴𝐹](𝜆𝑥:𝐹𝐴𝐹.𝑥):𝐹𝑃𝐹. Then the closed term 𝗃𝗎𝗇𝗄𝐵:=Λ𝐹::𝖳𝗒→𝖳𝗒.𝜆abs:𝖠𝖻𝗌𝐹.𝜆app:𝖠𝗉𝗉𝐹.𝜆tabs:𝖳𝖠𝖻𝗌𝐹.𝜆tapp:𝖳𝖠𝗉𝗉𝐹.tapp[𝑃𝐹]𝑞𝐹[𝑃𝐹](𝜆𝑧:𝑃𝐹.𝑞𝐹) has type 𝖤𝗑𝗉 ̂(𝐵→𝐵), because 𝗉𝗋𝖾𝐹(𝐵 →𝐵) =𝑃𝐹. It is not a quotation. A genuine outer type-application quotation clause has as its first child a quotation of a term with universal type, so its first type parameter has the form 𝗉𝗋𝖾𝐹(∀𝑢 ::𝜅.𝐶). Here that parameter is the arrow-normal constructor 𝑃𝐹, and its child 𝑞𝐹 is headed by the term-abstraction case. Constructor normalization and outer-form injectivity rule out their equality. The case interface is intentionally large enough to admit this well-typed, non-syntactic inhabitant.
Referenced from 3 locations
Suggested first pass.
Begin with exercise 17.7, reconstruct the open quotation argument in exercise 17.8, and test the boundary in exercise 17.9 before implementing the finite oracle.
★☆☆ For the quotation of (𝜆𝑥 :𝐼.𝑥) 𝗂𝖽𝐼, calculate the size fold and the outer-constructor test clause by clause. Compare the result with the source syntax tree, and identify the case or copied-variable contribution responsible for each unit in the returned Church numeral.
Referenced from 4 locations
★★☆ Generalize the deep quotation theorem to the one-variable judgment 𝑥 :𝐴 ⊢𝑒 :𝐵. State the type of the prequotation under the copied context, formulate the corresponding unquotation claim, and reconstruct the variable, both abstraction, both application, and conversion cases. Say precisely which closure step from theorem 7.68 is no longer available.
Referenced from 4 locations
★★☆ Use example 17.23 to prove that typing at 𝖤𝗑𝗉 ̂(𝐵→𝐵) does not characterize the quotation image, without using term strong normalization. Next suppose hypothetically that, for every closed type 𝐴, there is a total closed term 𝗊𝗎𝗈𝗍𝖾𝐴 :𝐴 →𝖤𝗑𝗉 ̂𝐴 whose result is stipulated to be the genuine quotation of each closed input. Determine whether these fixed-index quoters suffice to reinstate the diagonal obstruction from the opening section. Reconstruct the constructor equalities that the raw self-application would still require, and keep this typing calculation separate from the non-surjectivity argument and the normalization contradiction.
Referenced from 4 locations
★★★ Practical project.selfrepr-fold-checker Implement the finite four-constructor quotation and fold fragment in artifacts/ch17-fomega-selfrepr/corpus.kp. Stage 1 represents term and type abstraction and application as distinct data constructors. Stage 2 implements structural quotation/unquotation. Stage 3 implements the size and normality folds. Stage 4 rejects a distinguished inhabitant outside the quotation image. Maintain the invariant that unquoting a produced quotation recovers the original tree and that fold size agrees with direct size.
Run kappa check, kappa test, kappa run, and kappa audit. Acceptance is the six printed PASS lines and the final line All 6 typed-self- representation corpus cases passed., with an empty audit. Then replay separately the three README mutations: swap the two application children, omit the argument from the size fold, and accept a lambda-headed application as normal. Each mutant must still check but make kappa test fail. This finite oracle checks the displayed fold equations; it is not a proof of full 𝐹𝜔 kinding or normalization.
Referenced from 4 locations