Lectures onType Theory
ch:path-dependent-types: stable paths and pDOT
appendix sectionsolutions

ch:path-dependent-types: stable paths and pDOT

Exercise 108.1.

From r:Root, DOT-Rec-E exposes r:{palette:Palette}{default:r.palette.Color}. The first intersection projection and DOT-Fld-E give r.palette:Palette. Rule P-Var first gives rpath; the field typing just derived then gives r.palettepath by P-Fld. Eliminating the recursive palette type exposes its member declaration {Color:..}, so selection forms r.palette.Color. Finally the second root intersection projection gives r:{default:r.palette.Color}. Rule DOT-Fld-E derives r.default:r.palette.Color.

Exercise 108.2.

Let T0={a:p.A}{b:p.A},T1={a:q.A}{b:p.A},T2={a:q.A}{b:q.A}. The first Repl-pq instance changes only the occurrence in the a-field, using ΓReplace(T0,p,q,T1), and derives T0<:T1. The second uses ΓReplace(T1,p,q,T2) for the b-field and derives T1<:T2. Transitivity gives T0<:T2. Each indexed replacement derivation ends in R-Sel, whose second premise forms the complete changed selection Γq.Atype.

Exercise 108.3.

Extend the family by Treepal:=μ(t:{Node:..}{root:t.Node}{add:(n:t.Node)}{palette:Palette}), and replace Tree by Treepal in the three declarations of Γ. Recursion elimination at apple supplies the exact field premise Γapple:{palette:Palette}. Together with Γapplepath, obtained by P-Var, this is the premise of P-Fld; hence Γapple.palettepath,Γapple.palette.Colortype. The corresponding two premises for orange are Γorangepath,Γorange:{palette:Palette}. They yield the selected type orange.palette.Color.

Now use alias:orange.type. The first Sngl-E, with the target path orange.palette, derives Γalias.palette:(orange.palette).type. The second Sngl-E, with target path orange.palette.zero, derives Γalias.palette.zero:(orange.palette.zero).type. Field typing gives alias.palette.zero:alias.palette.Color, while Sngl-Trans and orange.palette.zero:orange.palette.Color give the same path the type orange.palette.Color.

Finally R-Sel constructs the one-occurrence replacement, and Repl-pq gives the requested agreement direction Γalias.palette.Color<:orange.palette.Color. Rule Repl-qp gives the converse. Thus the two selected Color types agree by mutual subtyping. The apple selection remains unrelated, as it should for a distinct tree family.

Exercise 108.4.

The displayed store yields the lookup chain Lookupγ(x)=ν(x){a=y.b},Lookupγ(x.a)=y.b,Lookupγ(y)=ν(y){b=ν(y){c=λ(z:).z}},Lookupγ(y.b)=ν(y){c=λ(z:).z},Lookupγ(y.b.c)=λ(z:).z. Rule Lookup-Path rewrites the pending x.a.c lookup through the intermediate alias y.b.c, after which Lookup-Val supplies the last line. Precise field typing gives x.a.c:(z:). With y:, dependent application therefore has type . Ordinary term progress first encounters the normal path x.a.c; exactly there lemma 108.9 ensures that extended reduction reaches the displayed lambda, enabling the beta step with y.

Exercise 108.5.

x is a stable path by P-Var; x.a.b is a stable path after two P-Fld instances, provided both field typings exist. Application (λy.y)x is rejected because the path grammar has no application clause. The object value ν(x:T)d is rejected because it has no object- construction clause. The whole let expression is rejected because it has no let clause, even though its bound expression and the body path y.b may separately be stable.

Exercise 108.6.

Install a root r whose palette field contains a tight member Color:T..T and a value zero:T, whose alias definition is the path r.palette, and whose default definition is r.alias.zero. Def-Path gives r.alias:r.palette.type. Since r.palette.Color is formed, singleton propagation and one-occurrence replacement give the two tight comparisons r.alias.Color<:r.palette.Color,r.palette.Color<:r.alias.Color. Field typing gives r.default:r.alias.Color; subsumption along the first comparison yields r.default:r.palette.Color. The derivation transports the selected type along the stable alias and does not assert raw syntactic equality of the paths.

Exercise 108.7.

Take Γ=q:,p:q.type{a:{A:..}}. The intersection component forms p.a.A, and the singleton component gives p:q.type. A root-only replacement would change that occurrence to q.a.A. Rule RP-Fld blocks it because P-Fld cannot derive Γq.apath from q:. Even if that premise were deleted, R-Sel would still require Γq.a.Atype, which also has no derivation. Thus the indexed prefix and complete-leaf checks reject the malformed replacement.

Exercise 108.8.

Let the enclosing object have stable path p, and let its nested field be a=ν(y:T)d. The installed inner self is the stable path p.a. Inverting Def-New gives the body judgment p.a;Γd[p.a/y]:T[p.a/y]. The tight-record premise supplies equal member bounds and pairwise distinct labels. Intrinsic well-formedness of the body derivation supplies the path-formation steps for every path in the two substituted expressions d[p.a/y]andT[p.a/y]. Rule Def-New has no separate path side condition. When the nested object is added to the store, extend the runtime context with p.a:μ(y:T) and with the precise field declarations obtained from T[p.a/y]. The body premise types the stored definitions at those declarations. Disjoint labels make field lookup unique. Hence the extended store matches the extended inert, well-formed context, and the surrounding installation term retains its type.

Search the book

Type to search the local edition.