Lectures onType Theory
ch:fomega-self-representation: ch:fomega-self-representation
appendix sectionsolutions

ch:fomega-self-representation: ch:fomega-self-representation

Exercise 7.16.

The type of the unquoter gives α::U;x:Expαunquote[α]x:OpIdα. Hence an application to the same x would require, for some formed type B, (1)OpIdα=βExpαB. The left side has the constructor reduction OpIdαβαId. Because α is a constructor variable, the application αId is neutral and constructor-normal. The right side of (1) has arrow head. Constructor confluence and disjointness of normal heads therefore refute (1).

Now let A be closed and let D:e:A be a closed derivation. Then D^:ExpA^, while type recovery gives the annotated chain OpIdA^βunfoldOp,A^preId(A)βlemma7.66A. Thus unquote[A^]D^ is well typed at A by constructor conversion. This calculation uses constructor normalization only; it makes no appeal to term strong normalization.

exercise 7.17.

The copied abstraction and polymorphic identity contain no application node, so the only inserted occurrence of i is at the root: (λx:I.x)idIshi[II](λx:I.x)idI. Substituting the closed polymorphic identity gives idI[II](λx:I.x)idIβ(λz:II.z)(λx:I.x)idIβ(λx:I.x)idIβidI. Before the substitution, the application is headed by the variable i. Its proper subterms are normal, so the prequotation is normal even though the represented source has a beta-redex at its root.

Exercise 7.18.

The recursively chosen constructors at the relevant kinds are STy=Y::Ty.Y,STyTy=λA::Ty.STy,Sκ=λF::TyTy.STy,κ=(TyTy)Ty. Rule K-All gives STy::Ty. Rule K-Abs first gives STyTy::TyTy and, with a binder of kind TyTy, gives Sκ::κ.

In the context X::Ty,T::κTy, put KX=λA::Ty.X. Then KX::TyTy and TSκ::Ty. Expand the stripping term as ΛB::Ty.λc:(C::Ty.KXCB).λx:(u::κ.KX(Tu)).c[TSκ](x[Sκ]). Under the three displayed term binders, universal elimination gives x[Sκ]:KX(TSκ),c[TSκ]:KX(TSκ)B,c[TSκ](x[Sκ]):B. Here KX(TSκ)βX, but conversion is not needed to match the argument and domain: they are already the same constructor expression. The two term lambdas and outer type lambda therefore give stripKX,κ,T:StripKX(u::κ.KX(Tu)).

For the calculation, let q have the type required under u::κ. Suppressing only annotations already displayed above, stripKX,κ,T[X](ΛC::Ty.λz:X.z)(Λu::κ.q)β(λc.λx.c[TSκ](x[Sκ]))(ΛC.λz:X.z)(Λu.q)β(λx.(ΛC.λz:X.z)[TSκ](x[Sκ]))(Λu.q)β(ΛC.λz:X.z)[TSκ]((Λu.q)[Sκ])β(λz:X.z)((Λu.q)[Sκ])β(λz:X.z)q[Sκ/u]βq[Sκ/u]. This is (7.10) at the stated higher kind.

exercise 7.19.

The term tree consists of a variable, a term abstraction, a constructor abstraction, and the final constructor application. Hence |e|=4. Its operator ΛA::Ty.λx:A.x is normal but not neutral, so the strengthened normality fold first produces TF. The final type-application case copies that pair’s neutral component, which is false, into both positions. It therefore produces FF, and the public projection gives isNormal[II^]D^βfalse. This agrees with the visible type-beta redex at the root. The same outer constructor makes isAbs[II^]D^ reduce to false, while the size theorem gives size[II^]D^β4.

Exercise 17.4.

The copied variable has type FZ. Thus the term-abstraction case is instantiated at source domain and codomain Z, giving qabs=abs[Z][Z](λz:FZ.z):F(FZFZ). Abstracting Z produces a family of type ΛZ::Ty.qabs:Z::Ty.F(FZFZ)=PF. Put TF:=preF(λZ::Ty.ZZ). Then TFZβ(FZFZ), so the strip term has type stripF,Ty,TF:StripFPF by constructor conversion. These are the two term arguments of the constructor-abstraction case, and therefore qtabs=tabs[PF]stripF,Ty,TF(ΛZ::Ty.qabs):FPF.

The source operator has universal type represented by PF, whereas the whole instance has arrow type represented by RF=FPFFPF. Hence the type-application interface first receives the operator index PF and its child qtabs:FPF. It then receives the result index RF and the instantiation map instPF,PF:PFFRF. Therefore q0=tapp[PF]qtabs[RF]instPF,PF:FRF. Reversing the two indices would require qtabs:FRF and is rejected before any reduction is considered.

Exercise 17.5.

Put P=preId(u::κ.A),Q=preId(C),R=preId(A[C/u]). After the recursive child has become q, the constructor-application branch is (ΛX.λf:X.ΛY.λg:XY.gf)[P]q[R](λx:P.x[Q]). Keeping the type-beta and term-beta contractions separate gives (ΛX.λf:X.ΛY.λg:XY.gf)[P]q[R](λx:P.x[Q])βtypeβ(λf:P.ΛY.λg:PY.gf)q[R](λx:P.x[Q])βtermβ(ΛY.λg:PY.gq)[R](λx:P.x[Q])βtypeβ(λg:PR.gq)(λx:P.x[Q])βtermβ(λx:P.x[Q])qβtermβq[Q]. The induction hypothesis gives qβe under the constructor variable u. The first use of type recovery is QβC; compatible mixed reduction therefore gives q[Q]βe[C]. The second use is RβA[C/u], which converts the branch result type to the source result type. The operator index P already has universal outer form by its definition, so no third recovery step is needed to form q[Q].

Exercise 17.7.

The source tree has an application root, a term-abstraction operator, and the closed identity argument. Counting the identity as its type abstraction, term abstraction, and variable body gives six nodes. The fold visits each child before the application case. Each copied variable is replaced by one in the strengthened size proof; each unary abstraction case applies successor to its child’s count; and the application case returns one plus the two child counts. Thus 1+(1+1)+(1+(1+1))=6. The outer-constructor fold ignores both recursive results and selects its application result, so it returns false for the abstraction test. Both answers follow the displayed source tree rather than its beta-normal form.

Exercise 17.8.

Under x:A, the fundamental lemma gives a prequotation F::TyTy;x:FpreF(A),ΞFq:FpreF(B). After substituting Id and the four unquoting cases, the open claim is qβe under x:A, up to the constructor conversions supplied by type recovery. The variable case is the copied variable. The term-abstraction case contracts unAbs and applies the induction hypothesis below the binder; the term-application case contracts unApp, then applies the two induction hypotheses. In the type-abstraction case, unTAbs discards its strip argument and returns the copied type abstraction, after which compatible reduction applies the induction hypothesis below the type binder. In the type-application case, unTApp applies inst to the recursively unquoted operator. Expanding inst yields q[Q], where Q=preId(C), and type recovery converts (Q) to the source argument (C). Conversion changes no term, so the same induction hypothesis is reused at the converted result type. What is unavailable is the closure step used in the closed quotation theorem. The term q still has the free variable x:FpreF(A). Abstracting F and the four cases alone would leave a free variable whose type contains the bound F, so it does not produce a term of ExpB^. The prequotation and its unquotation property remain valid as open judgments.

Exercise 17.9.

The term junkB has the required representation type by the four case interfaces. Its outer tapp child is nevertheless headed by abs at the arrow-normal index PF. In a genuine type-application quotation, that child quotes an operator of universal type, so its first index is the representation of a universal. Constructor normalization and injectivity of outer normal forms separate these shapes. Thus junkB is well typed but outside the quotation image; no normalization contradiction is needed.

An internal quoter at each fixed index would still not supply the typing equalities required by the diagonal. Write Q(A):=ExpA^ and suppose, hypothetically, that quoteA:AQ(A) is available for each closed A. If uA:Q(A)A, then typing (uAx)x for x:Q(A) first requires A=βQ(A)B for some B. If the resulting diagonal term has type P, its quotation has type Q(P), while the diagonal term expects Q(A); self-application therefore also requires Q(P)=βQ(A). To use the unquoting equation at that quotation requires P=βA. The hypothetical family of quoters establishes none of these constructor equalities. Thus it does not by itself reinstate the raw diagonal. Strong normalization is used only after the missing equalities are assumed and the forbidden application has thereby been made well typed.

Search the book

Type to search the local edition.