Lectures onType Theory
ch:dependent-staging: ch:dependent-staging
appendix sectionsolutions

ch:dependent-staging: ch:dependent-staging

Exercise 130.1.

From Γv:VecAn@ε, rule MD-CSP derives Γ%αv:VecAn@α; the corresponding type is well formed at α by MD-TCSP. Rule MD-Quote therefore gives Γ%αvα:α(VecAn)@ε. After removing %α, the quotation premise would require Γv:VecAn@α. The declaration of v is at ε, and MD-Var requires an exact stage match, so that premise fails.

Exercise 130.2.

Inversion of the redex typing gives ΓΛα.M:α.τ@A and hence, after renaming α fresh for Γ,A,B, the premise ΓM:τ@A. Rule MD-SApp types the redex at τ[B/α]@A. The stage-substitution clause of lemma 130.3 yields Γ[B/α]M[B/α]:τ[B/α]@A[B/α]. Freshness makes the context and A unchanged, giving exactly the type of the contractum. If the result type were left as τ, a free occurrence of α in τ would remain after its binder disappeared; the claimed conclusion would be ill formed and would not match the MD-SApp conclusion.

Exercise 130.3.

Write the outer redex as (Λα.M)B. If MM, the peak is (Λα.M)BM[B/α],(Λα.M)B(Λα.M)B. Compatibility of stage substitution with full reduction, proved by induction on the inner reduction, gives M[B/α]M[B/α]. Stage substitution does not duplicate a term occurrence, but it can expand one labelled escape–quotation pair into a shell containing |B| primitive splices. For example, with a constant c and B=βγ, take M=αcαα. After the outer stage-beta step its residual inner redex is qβγ(eβγ(qβγ(c))). Contract the β-splice and then the γ-splice to obtain qβγ(eβγ(qβγ(c)))β-spliceqβγ(eγ(qγ(c)))γ-spliceqβγ(c). For a word of length n, the same shell induction transports the residual through exactly n primitive splice contractions; for the empty word the two substituted endpoints coincide. Contracting stage beta on the right gives M[B/α]. Thus the residual inner step is transported through stage substitution, while the residual outer redex remains at the root of (Λα.M)B.

For the splice peak, write the term as αMα with an ordinary beta step MM. The root step yields M, which takes that beta step to M. Quotation and escape compatibility yield αMα, whose root splice step also yields M. These are the two required common reducts.

Exercise 130.4.

Use the signature constants a0,a1:A from the chapter. Persist them and form at stage α v2=cons1(%αa1)(cons0(%αa0)nil):VecA2@α. Then MD-Quote gives v2α:α(VecA2)@ε. The generator is the empty-stage term G2=v2α; staged evaluation stops immediately at that quotation because its constant-headed constructor applications at stage α are future-stage values, not contractions. Inverting its type with lemma 130.2 verifies the body judgment at the extended stage α. The CSP markers make persistence explicit but are removable by MD-Q-Percent, since MD-Const types the signature constants at both stages. This closed example therefore satisfies the empty-stage hypothesis of theorem 130.15.

Exercise 130.5.

Start generation in the empty store. Allocation chooses its least unused location, so (,new0)({00},0). Unrestricted CSP constructs the code value C=!(%α0)α. The generation boundary returns C and discards the generation store, leaving (,C).

For the first later evaluation, allocation again chooses location zero: (,new0)({00},0),({00},!0)({00},0). For the second, the same rule with initializer one gives (,new1)({01},0),({01},!0)({01},1). The identical closed code value C therefore returns zero or one according to a store allocated after generation. A canonical-forms argument that treats a closed code value as carrying every resource needed by its body is false; equivalently, the store-independent reduct assumed when commuting a generated code step with an unrelated later allocation is false. The pure calculus’s CSP rule therefore requires a world/store discipline before it can persist locations.

Search the book

Type to search the local edition.