Lectures onType Theory
ch:dependent-session-types: dependent sessions
appendix sectionsolutions

ch:dependent-session-types: dependent sessions

Exercise 102.1.

Induct on A. Constructors without binders commute with substitution by the induction hypotheses on their immediate components. For a universal, alpha-rename its binder to yFV(M){x}. Then (y:τ.B)[M/x]=y:τ[M/x].B[M/x]=y:τ[M/x].B[M/x]=IHy:τ[M/x].B[M/x]=(y:τ.B)[M/x]. For an existential, use the same fresh y and calculate (y:τ.B)[M/x]=y:τ[M/x].B[M/x]=y:τ[M/x].B[M/x]=IHy:τ[M/x].B[M/x]=(y:τ.B)[M/x]. If the outer binder were also named x, substitution would stop at that binder; if it occurred free in M, substitution without alpha-renaming would capture it. The fresh y makes both sides use the same capture-avoiding operation.

Exercise 102.2.

Let v3=consa(consb(conscnil)), so Ψv3:Vec(E,3). Two applications of R derive the provider, first with witness 3, then with witness v3; dually the client uses L twice. The first communication leaves v:Vec(E,3).1, and the second leaves 1. Both cut classifiers are identical after each functional substitution. If v2:Vec(E,2) replaces v3, the first step still fixes the continuation index at three. The term premise Ψv2:Vec(E,3) required by the second R has no derivation, so the trace is rejected before its second communication.

Exercise 102.3.

Take an environment endpoint y:n:Nat.1. Rule 1R derives n:Nat;;0::z:1, and 1L adds the inert assumption y:1. From that premise, rule L derives the live process ;;y:n:Nat.1y(n).0::z:1. It is well typed, offers 1, and is live because it contains the input prefix. It is not closed: its linear environment contains y. No local reduction applies until a provider sends a witness on y. Thus every premise of theorem 102.9 except the empty linear context is represented, and the missing premise is exactly what permits the exposed environment action instead of a reduction.

Exercise 102.4.

At index n=3, the guard is evaluated before a branch is selected at every unfolding. The successive positive indices 3,2,1 select the message branch, while 0>0 is false. Thus array(τ,3)=msg(S,int(3))::msg(S,τ)::=msg(S,τ)::msg(S,τ)::end(S). If the guard is changed to n0 over the integers, the terminating branch is never reached: at n=0 the message branch is selected and the recursive index becomes 1, after which every further index still follows the recursive definition under the erroneous guard. The first wrong branch selection therefore occurs at n=0.

Exercise 102.5.

Choose a fresh functional name aFV(M)dom(Ψ). The provider ends in R with ΨM:τ,Ψ;Γ;Δ1P::x:A[M/a], and the client ends in L with Ψ,a:τ;Γ;Δ2,y:AQ::z:C. Before reduction the cut uses the disjoint split Δ1Δ2. Functional substitution turns the client premise into Ψ;Γ;Δ2,y:A[M/a]Q[M/a]::z:C[M/a]. The principal cut therefore reduces to (νy)(PQ[M/a]), whose provider and client classifiers are both A[M/a]. Channel substitution removes y and retains the same union Δ1Δ2; no linear declaration is duplicated.

Exercise 102.6.

The companion prints rejected: expected Vec 2. The failed premise of R is ΨM:τ at τ=Vec(E,2). Its length-one witness derives only Ψw1:Vec(E,1), so the required premise cannot be constructed. This finite rejection does not establish theorem 102.8: that theorem also assumes that every linear declaration occurs in exactly one premise of each multiplicative rule, a property of complete derivations rather than of one execution trace.

Exercise 102.7.

Use PositiveFin=n:Nat.p:(n>0).i:Fin(n).1. For n=2, transmit the canonical proof p2:2>0, then fzero:Fin(2). Successive substitutions leave p:(2>0).i:Fin(2).1, then i:Fin(2).1, then 1. For a rejected trace, first transmit 1 but next supply p2:2>0. The second R requires a term of type 1>0, whereas p2 has type 2>0; conversion cannot identify the two indices. Alternatively, a later i:Fin(2) fails the required Fin(1) premise. Proof irrelevance would identify proofs already inhabiting one proposition; it would not convert 2>0 into 1>0. Adding it changes equality and requires a separate preservation and erasure argument.

Search the book

Type to search the local edition.