Lectures onType Theory
ch:erasure-execution: ch:erasure-execution
appendix sectionsolutions

ch:erasure-execution: ch:erasure-execution

Exercise 126.1.

Rule Rel-Var gives Γy runtime. In Γ,zruntime:2, a second instance gives z runtime; hence Rel-Lam-R derives runtime relevance of the displayed abstraction. Rule Rel-App-R applied to those two premises derives runtime relevance of the application.

Suppose the Boolean eliminator had a runtime-relevance derivation. Inversion leaves only Rel-Bool-Elim, whose scrutinee premise is Γx runtime. Inversion of a runtime judgment for a variable leaves Rel-Var, but Γ contains xerased:2, not a runtime-marked binding. Thus the scrutinee premise is missing. Rule Rel-Erased cannot repair it because its conclusion is the erased judgment.

Exercise 126.2.

The runtime-field list is run(pack)=(2), so |pack(suc0,tt)|=Cpack(Ctt). The source branch erases to Cpack(b)C0. The erased index binder i has no target position. The Boolean field is a retained constructor field, so it contributes the binder b even though the independent branch-use mark is erased and b does not occur in the body. Deleting that binder would give the branch arity zero while the tag has arity one, violating representation well-formedness and preventing E-Case from installing the constructor payload.

Exercise 126.3.

Source substitution gives e[tt/x]=(tt,refltt), and therefore |e[tt/x]|=Cpair(Ctt,Crefl). On the other side, |e|[|tt|/x]=Cpair(x,Crefl)[Ctt/x]=Cpair(Ctt,Crefl). The reflexivity clause emits the nullary tag Crefl; its endpoint is a source annotation and contributes no target variable.

Exercise 126.4.

Erasing the element type, both lengths, and predecessor indices leaves the closure |append|=clos(append,) and the two runtime arguments. Abbreviate p=Cvcons(a,Cvnil) and q=Cvcons(b,Cvnil). First derive D0:call(|append|,Cvnil,q)q. Its outer rule is E-Call: E-Val supplies the closure and both arguments, while its body premise is an E-Case derivation whose scrutinee and selected Cvnil branch both use E-Val. The complete call is the derivation call(|append|,p,q)Cvcons(a,q). Its outer E-Call again evaluates the closure and arguments by E-Val. The body premise uses E-Case to select the Cvcons branch. That branch uses E-Con, with E-Val for a and D0 for the recursive field. Hence the target constructor tree is Cvcons(a,Cvcons(b,Cvnil)), and both case selections inspect only retained vector tags.

Exercise 126.5.

Put q0=Cstream(clos(h,C0),clos(t,C0)). For the head word, Obs-Head forces clos(h,C0); its E-Call body evaluates to C0. Thus Obs(q0,head,C0). For the tail word, Obs-Tail first forces clos(t,C0). Its E-Call derivation evaluates the transition once and returns q1=Cstream(clos(h,Csuc(C0)),clos(t,Csuc(C0))). The remaining Obs-Head premise forces the head closure of q1, whose E-Call result is Csuc(C0). These premises derive the second requested observation.

Exercise 126.6.

The four index-erasure clauses give (iN.VecA{i}N)=ListAN. The outer index-polymorphic binder disappears, and the index abstraction and application inside VecA{i} disappear. The Curry term inhabiting the type is unchanged.

Exercise 126.7.

The constructor clauses are vnilRCvnil,aRaxsRxsvcons(n,a,xs)RCvcons(a,xs). For a source constructor evaluation, apply the induction hypothesis to every runtime field. The erased index n produces no target field, so the target forms the declared arity-two block and the second displayed relation applies. For a recursive branch body e, retained bindings satisfy |e[a/x,xs/y]|=|e|[a/x,xs/y] by two instances of lemma 126.11; substitution for the erased predecessor index disappears by its erased clause. The target therefore selects the matching constructor branch and preserves R.

Exercise 126.8.

Let b=λerasedx:2.if x then 0 else 1. Then btt0 and bff1. Under the unsafe erasure clauses, both applications erase their argument and abstraction, so both yield the same phrase |if x then 0 else 1|. The phrase is open because the erased binder supplies no target x, already violating target well-formedness. Any deterministic repair that closes the phrase has one outcome, and therefore cannot relate simultaneously to the distinct canonical source values zero and one. Runtime relevance rejects b before this contradiction arises.

Search the book

Type to search the local edition.