Lectures onType Theory
ch:coercive-subtyping: coherent casts
appendix sectionsolutions

ch:coercive-subtyping: coherent casts

Exercise 119.1.

The first derivation synthesizes x:A, inserts a:AB, and then inserts c:BD, producing c(a(x)). The second inserts b:AC and then d:CD, producing d(b(x)). Coherence requires the target-theory function equality Γλx.c(a(x))λx.d(b(x)):AD. An equality after substituting one selected x:A does not compare the cast programs at all inputs and therefore does not satisfy path coherence.

Exercise 119.2.

The permitted derivation synthesizes (x,y):A×B by Coe-Pair and checks it at 2 by one Coe-Insert along σ, yielding tt. The attempted second derivation tries to check x:A at A inside Coe-Pair; that premise cannot use Coe-Insert, because Coe-Pair demands synthesis for both components. The programmer can write the annotation (x:A), which lets Coe-Ann synthesize A after checking x along ι. The pair then synthesizes A×B, and final insertion along τ yields ff.

Exercise 119.3.

The domain path is contravariant: pCoe(A2,A1). For each x:A2, the codomain path is qxCoe(B1(progpx),B2(x)). Given f:Πy:A1.B1(y), first progpx:A1, then f(progpx):B1(progpx), and finally progqx(f(progpx)):B2(x). Abstraction over x and f gives the cast from Πy:A1.B1(y) to Πx:A2.B2(x). Reversing p would make the first application ill typed at x:A2.

Exercise 119.4.

For r:Rec1, the first field is progp(r.n):N. The second is progqr.n(r.v):VecA(progp(r.n)), because r.v:VecA(r.n) and qr.n has the corresponding dependent source and target. Thus the full cast is (progp(r.n),progqr.n(r.v)):Rec2. For p=id, choosing qn=mapα gives the well-typed second field mapα(r.v):VecA(r.n). If progp=suc, the required type is instead VecA(suc(r.n)); reusing mapα(r.v):VecA(r.n) is ill typed.

Exercise 119.5.

Write the dependent application premises before completion as Γf:(x:K1)K2,Γt:K1. Completing their derivations separately may instead produce Γf:(x:K1)K2,Γt:K1. The application rule can be rebuilt only after proving Γ=TΓ and K1=TK1. Basic-edge coherence does not itself establish either equality. Lemma 5.3 shows that the operations used while completing derivations preserve equality of the relevant presupposed judgments, and Corollary 3.6 supplies coherence in T[R]0K. Lemma 5.7 then proves derivation independence where both completion images are defined, and Theorem 5.8 proves totality.

Section 4 leaves open a simple general condition on arbitrary rule forms of T and arbitrary basic-rule systems R that guarantees this argument that matches these presuppositions. The proved result covers the displayed logical-framework systems, the stated coherent rule sets, and the cited inductive schemata.

Search the book

Type to search the local edition.