Lectures onType Theory
Chapter 102
Chapter 102Optional

Dependent Session Types and Protocol-Indexed Programming

Prerequisites. Direct starred prerequisites: Chapter 21, Chapter 40. No later core chapter depends on this route.

The protocol NatVecend of chapter 21 lets a provider send a natural number, then a vector, then stop. It does not require the vector length to equal the transmitted number. Replacing the second payload by a family Vec(n) creates a binding problem: communication must substitute the received numeral into every later protocol, while the channel itself must still be used exactly once.

A dependent proposition is a protocol

Definition 102.1 — Dependent-session signature

Fix a total dependent functional language with judgments ΨM:τ and capture-avoiding substitution. Session types extend the binary connectives of chapter 21 by two dependent quantifiers and one value-transport type: A,B::=1ABABABA&B!Ax:τ.Ax:τ.A$τ. Processes are generated by the following productions. The alternation bar of the grammar begins a line; a bar inside a production, as on the second line, is parallel composition of two processes. P,Q::=0inactionPQparallel composition(νx)Pchannel restrictionxy.Psend a fresh channel yx(y).Preceive a channel or an index!x(y).Preplicated channel inputxM.Psend the functional term Mx.inl;Pselect the left branchx.inr;Pselect the right branchx.case(P,Q)offer two branches[xy]forwarder[xM]value transport The process judgment Ψ;Γ;ΔP::z:A means that P offers session A along z, using functional variables Ψ, persistent channels Γ, and linear channels Δ. The domains of Γ and Δ are disjoint. Every declaration in Δ occurs in exactly one premise of a multiplicative rule.

The process relation used below is the source relation, not an unspecified compatible closure.

Definition 102.2 — Structural congruence and reduction

Write P=scQ when P and Q are structurally congruent. This is the least congruence containing alpha-equivalence and P0=scP,PQ=scQP,P(QR)=sc(PQ)R,xfn(P)P(νx)Q=sc(νx)(PQ),(νx)0=sc0,(νx)(νy)P=sc(νy)(νx)P,[xy]=sc[yx]. Root reduction consists of the seven communication rules xy.Qx(z).P  QP[y/z],xy.Q!x(z).P  QP[y/z]!x(z).P,xM.Qx(z).P  QP[M/z],(νx)([xy]P)  P[y/x],(νx)([xM]P)  P[M/x],x.inl;Px.case(Q,R)  PQ,x.inr;Px.case(Q,R)  PR. It is closed by parallel composition and restriction: QQPQPQ,PQ(νy)P(νy)Q, and by structural congruence: if P=scP, PQ, and Q=scQ, then PQ. These clauses define every use of through theorem 102.8, theorem 102.9.

Eighteen rules are inherited unchanged from the propositions-as-sessions reading of chapter 21. They are collected here because the preservation proof below rebuilds each of them.

Ψ;Γ;x:A[xz]::z:A
Id
Ψ;Γ;0::z:1
Ψ;Γ;ΔP::z:C
Ψ;Γ;Δ,x:1P::z:C
Ψ;Γ;Δ1P::y:AΨ;Γ;Δ2Q::z:B
Ψ;Γ;Δ1,Δ2(νy)zy.(PQ)::z:AB
Ψ;Γ;Δ,y:A,x:BP::z:C
Ψ;Γ;Δ,x:ABx(y).P::z:C
Ψ;Γ;Δ,x:AP::z:B
Ψ;Γ;Δz(x).P::z:AB
Ψ;Γ;Δ1P::y:AΨ;Γ;Δ2,x:BQ::z:C
Ψ;Γ;Δ1,Δ2,x:AB(νy)xy.(PQ)::z:C
Ψ;Γ;ΔP::z:AΨ;Γ;ΔQ::z:B
Ψ;Γ;Δz.case(P,Q)::z:A&B
Ψ;Γ;Δ,x:AP::z:CΨ;Γ;Δ,x:BQ::z:C
Ψ;Γ;Δ,x:ABx.case(P,Q)::z:C
⊕L
Ψ;Γ;Δ,x:AP::z:C
Ψ;Γ;Δ,x:A&Bx.inl;P::z:C
_1
Ψ;Γ;ΔP::z:A
Ψ;Γ;Δz.inl;P::z:AB
⊕R_1

The companion rules &L2 and R2 replace inl by inr, A by B in the premise, and nothing else. Replication is

Ψ;Γ;P::y:A
Ψ;Γ;!z(y).P::z:!A
!R
Ψ;Γ,u:A;ΔP::z:C
Ψ;Γ;Δ,x:!AP[x/u]::z:C
!L
Ψ;Γ,u:A;Δ,y:AP::z:C
Ψ;Γ,u:A;Δ(νy)uy.P::z:C
Copy

and the two cuts are

Ψ;Γ;Δ1P::x:AΨ;Γ;Δ2,x:AQ::z:C
Ψ;Γ;Δ1,Δ2(νx)(PQ)::z:C
Cut
Ψ;Γ;P::x:AΨ;Γ,u:A;ΔQ::z:C
Ψ;Γ;Δ(νu)((!u(x).P)Q)::z:C
Cut^!

Six rules are new, and the smallest pair comes first. The transport type $τ, written with a dollar sign because it imports a functional value into the session language, internalizes a checked term as a session. Its right rule offers such a value; its left rule changes one linear channel assumption into a functional assumption:

ΨM:τ
Ψ;Γ;[zM]::z:$τ
Ψ,x:τ;Γ;ΔP::z:C
Ψ;Γ;Δ,x:$τP::z:C

The process term in the conclusion is the same syntax P; the rule changes the sort of the name x. A cut against $R performs the delayed functional substitution: (νx)([xM]P)P[M/x]. A bank that receives an identifier and a deposit and then stops offers TBank:=$string($nat1), and the process x(s).x(n).0 offers it along x. Nothing in that type relates s to n. Making the second payload depend on the first is what the quantifiers below add.

The source writes dependent quantifiers as behavioral input and output:

Definition 102.3 — Dependent quantifier rules

Ψ,x:τ;Γ;ΔP::z:A
Ψ;Γ;Δz(x).P::z:x:τ.A
ΨM:τΨ;Γ;Δ,y:A[M/x]P::z:C
Ψ;Γ;Δ,y:x:τ.AyM.P::z:C
ΨM:τΨ;Γ;ΔP::z:A[M/x]
Ψ;Γ;ΔzM.P::z:x:τ.A
Ψ,x:τ;Γ;Δ,y:AP::z:C
Ψ;Γ;Δ,y:x:τ.Ay(x).P::z:C

The beta communication is (νy)(y(x).PyM.Q)(νy)(P[M/x]Q). The substitution in the reduct acts on functional terms, process terms, session types, and channel classifiers.

In the intuitionistic presentation, a right rule describes the provider and a left rule describes the client; typing requires no endpoint duality operator. A two-ended interface needs one, and chapter 21 already fixes it on the binary connectives. Only the two quantifiers and the transport type are new.

Definition 102.4 — Quantifier duality

On the fragment without the shared service type !A, extend the duality of chapter 21 by x:τ.A=x:τ.A,x:τ.A=x:τ.A,$τ=$τ. The inherited clauses are unchanged, and in particular AB=AB,AB=AB.

Read the two inherited clauses carefully, because the tempting variant is wrong. In R the provider creates a fresh channel y and itself offers A on it; in L the client receives y as an assumption y:A. Both endpoints therefore name the transmitted channel by the same type A, and duality must leave the payload alone. Writing AB instead would dualize a channel that no endpoint ever reads from the other side; chapter 21 rejects it for the same reason and restricts syntactic duality to closed message types. The quantifier clauses are safe because τ is a functional type, not a session type, so there is nothing in τ to dualize.

Both new clauses are involutive, and $τ is self-dual because value transport moves a functional term in one direction only. None of them adds a rule to the source calculus.

Lemma 102.5 — Quantifier communication fidelity

Suppose the provider and client derivations end in matching R/L rules, or matching R/L rules. Their cut reduces to a cut whose two channel classifiers are both A[M/x].

Proof of Lemma 102.5 — Quantifier communication fidelity

Proof. For , the provider continuation is derived under x:τ with offered type A. The client premise contains y:A[M/x]. Functional substitution in the provider derivation gives offered type A[M/x], so the reduct (νy)(P[M/x]Q) is a cut on that same type. For , the provider premise already offers A[M/x], and substitution in the client premise changes its assumption from A to A[M/x]. Thus both quantifier pairs produce the displayed classifier. ◻

Exercise 102.1

★☆☆ For A in the shared-free fragment, prove by induction on A that A[M/x]=A[M/x]. Write the two quantifier cases and state why capture-avoiding renaming is needed when the outer binder has the same name as x.

An indexed transfer

Let Vec(E,n) be the functional type of vectors of elements of E and length n. A provider that first receives a length and then a matching vector offers RecvVec(E):=n:Nat.v:Vec(E,n).1. A dual sender offers the existential interface SendVec(E):=n:Nat.v:Vec(E,n).1. Let a,b:E and put w2:=consa(consbnil):Vec(E,2),w1:=consanil:Vec(E,1). If the sender chooses the witness 2 and then the witness w2, the two communications calculate the residual protocol as (n:Nat.v:Vec(E,n).1)[2/n]=v:Vec(E,2).1,(v:Vec(E,2).1)[w2/v]=1. Sending w1 instead fails at the second step. Rule R requires Ψw1:Vec(E,2), and w1 has type Vec(E,1); the first witness fixes the index at 2. The rejection occurs in the functional premise of the typing rule, before any communication happens.

A proof-relevant branch can transmit n:Nat.p:Even(n).(HalfPayload(n,p)Reject). The continuation may depend on the proof p, not merely on the Boolean fact that n is even. Erasing p requires the separate proof-irrelevant extension and its erasure theorem; dependent sessions alone do not erase it.

Exercise 102.2

★★☆ Derive the provider and client rules for a transfer of a length-three vector. Perform the two communication steps and write the residual type after each substitution. Replace the vector by length two and identify the first premise that has no derivation.

Two substitutions

Functional substitution changes indices everywhere. Channel substitution composes processes and splits only the linear channel context. Conflating them loses the invariant needed by preservation.

Lemma 102.6 — Functional weakening and substitution

If ΨM:τ, then:

  1. a derivation under Ψ remains derivable under Ψ,x:σ, provided x is fresh for the derivation;

  2. from Ψ,x:τ,Ψ;Γ;ΔP::z:A one derives Ψ,Ψ[M/x];Γ[M/x];Δ[M/x]P[M/x]::z:A[M/x].

Proof of Lemma 102.6 — Functional weakening and substitution

Proof. Weakening is induction on the functional or process derivation. The quantifier binder case alpha-renames its bound name to a name outside FV(M)dom(Ψ,Ψ).

For substitution, induct on the process derivation while using the functional substitution theorem in every term premise. In R, choose yFV(M)dom(Ψ,Ψ); the induction hypothesis yields the substituted body under y:σ, and the rule rebuilds the quantified conclusion. In L, functional substitution gives the witness type and the process induction hypothesis gives the continuation with classifier B[N/y][M/x]. The fresh choice gives B[M/x][N[M/x]/y], the classifier required by the rebuilt rule. The two existential cases use the same commutation equation, with right and left rules exchanged.

It remains to check twenty concrete rules, or eighteen rule schemas when the two branch indices are grouped. Put θ=[M/x],Ψ^=Ψ,Ψ[M/x]. Write a superscript ()θ for simultaneous capture-avoiding action on channel contexts, processes, and offered types. The cases fall into the following exhaustive forms.

The nullary cases are Id, 1R, and $R. For Id, substitution changes only the classifier: Ψ^;Γθ;y:Aθ[yz]::z:Aθ. Rule 1R is unchanged because its linear context and offered type contain no index. In $R, functional substitution first changes its sole premise Ψ,x:τ,ΨN:σ into Ψ,ΨθNθ:σθ; rebuilding $R gives [zNθ]::z:$σθ.

Four rules split a linear context. The representative R case is Ψ^;Γθ;Δ1θPθ::y:AθΨ^;Γθ;Δ2θQθ::z:BθΨ^;Γθ;Δ1θ,Δ2θ(νy)zy.(PθQθ)::z:AθBθ. The induction hypotheses supply its two premises. Since θ changes classifiers but no channel name, dom(Δ1θ)dom(Δ2θ)=. Rule L is this schema with the first result channel sent to the second premise. Rule Cut replaces the displayed output constructor by (νy)(PθQθ). Rule Cut! has an empty first linear context and puts its cut formula in the persistent context of the second premise. Functional substitution preserves both facts, so those three rules rebuild without an additional structural principle.

Two rules have two premises with the same linear context. For &R, the two induction hypotheses have exactly Δθ and rebuild z.case(Pθ,Qθ). For L, they have Δθ,y:Aθ and Δθ,y:Bθ, respectively, and rebuild y.case(Pθ,Qθ). Thus neither case silently turns a shared context into a split one.

The remaining unary cases are exact instances of (U)Ψ^;Γθ;(Δ,y:A)θPθ::z:CθΨ^;Γθ;(Δ,y:F(A))θFy(Pθ)::z:G(A,C)θ, where F,Fy,G are the constructors printed on the corresponding rule. The exact instances are as follows. Rule 1L deletes the unused y:1 from the premise. Rule L replaces premise entries w:A,y:B by the one conclusion entry y:AB. Rule R abstracts the premise entry y:A and offers AB. Rules &L1 and &L2 select A and B, respectively; rules R1 and R2 make the corresponding offered choice. Because substitution commutes with each type constructor, for example (AB)θ=AθBθ, each conclusion is the required instance of (U).

For !R, the induction hypothesis retains the empty linear context. For !L, it changes the persistent premise entry u:A to u:Aθ and the linear conclusion entry y:!A to y:!Aθ. The Copy case changes both its persistent u:A and fresh linear y:A entries to Aθ; the side condition that y is fresh is preserved because θ introduces no channel names. Finally, $L is alpha-renamed so that its channel name y is different from the substituted functional variable x. Its induction hypothesis changes the premise functional entry from y:σ to y:σθ, and $L rebuilds the conclusion entry y:$σθ. These nullary, split, same-context binary, unary, and four quantifier cases cover every rule in definition 102.1, definition 102.3. ◻

Composition of processes is Cut, and nothing has to be proved to compose them: the rule is the composition principle, and its disjointness side condition is what makes the composite linear. What does have to be proved is that composing a matching provider and client produces a step, and that the step leaves a well-typed process behind. Lemma 102.7 states that fact; it is the only channel-level result the preservation proof needs.

Lemma 102.7 — Principal communication

Let Ψ;Γ;Δ1P::x:A,Ψ;Γ;Δ2,x:AQ::z:C, with dom(Δ1)dom(Δ2)=, so that Cut derives Ψ;Γ;Δ1,Δ2(νx)(PQ)::z:C. If in addition P ends in the right rule for A and Q in a left rule for A, then the following alternatives hold.

  1. If A!B, the cut reduces, and its reduct is derivable at the same conclusion Ψ;Γ;Δ1,Δ2::z:C using only cuts on the immediate subformulas of A.

  2. If A=!B, proof conversion changes the ordinary cut to a persistent cut without a process step. Whenever its client exposes a Copy request, the request reduces to one cut on B, and the replicated provider remains available in Γ.

Proof of Lemma 102.7 — Principal communication

Proof. By cases on the cut formula A. Each nonpersistent case exhibits the step and then the rebuilt derivation; the conclusion is the same in every case, so only the cut structure changes. The persistent case exhibits first the proof conversion and then the step triggered by Copy.

For y:τ.B, the provider receives a term by R and the client sends one by L. lemma 102.5 gives both residual classifiers as B[M/y], so the reduct is one cut on B[M/y]. For the polarities are exchanged and the same lemma applies.

For A1A2, the provider is (νy)xy.(P1P2) with P1::y:A1 and P2::x:A2, and the client is x(y).Q with y:A1,x:A2 among its assumptions. The step is (νx)((νy)xy.(P1P2)x(y).Q)(νx)(P2(νy)(P1Q)). Read the reduct carefully, because it is not what a substitution lemma would produce. The name x survives: the inner cut composes P1 and Q on the fresh y at type A1, and the outer cut still composes P2 and that composite on x, now at the residual type A2. One cut at A1A2 has become two, at A1 and at A2; the channel is consumed only when its type is finally 1. A1A2 is the same step with provider and client exchanged.

For A1A2, the selection prefix x.inl meets x.case and the reduct discards the unselected branch, leaving one cut on A1 along the same x; & exchanges the two sides. For 1 the provider is 0 and the client continues, so the cut disappears and x is consumed — this is the one case in which it is. For $τ the delayed functional substitution of definition 102.2 fires and x changes sort from a linear channel to a functional assumption.

For !B, the principal proof reduction first turns the ordinary cut against !L into the persistent cut (νu)(!u(y).P0Q), where P0::y:B has no linear assumptions and Q uses u:B only through Copy. A particular copy has process (νv)uv.R. Scope extrusion exposes the root step uv.R!u(y).P0RP0[v/y]!u(y).P0. The request channel v is linear and the resulting cut formula is the immediate subformula B. The replicated input remains available, but its contraction is confined to the persistent declaration u:B in Γ; no declaration of Δ1,Δ2 is copied.

In every case the conclusion retains the union Δ1,Δ2, and disjointness is what lets the two premises be recombined without a name clash. ◻

Dropping disjointness from Cut permits both premises to use one linear channel, and the conclusion then duplicates it. Dropping totality of the functional language can make equality checking of protocol indices diverge. These hypotheses have different roles and neither follows from the other.

Preservation and closed progress

Theorem 102.8 — Type preservation

If Ψ;Γ;ΔP::z:A and PQ, then Ψ;Γ;ΔQ::z:A.

Proof of Theorem 102.8 — Type preservation

Proof. Induct on the typing derivation. A principal cut is lemma 102.7, whose statement already gives the rebuilt derivation at the same conclusion. The dependent quantifier cases of that lemma rest on lemma 102.5, and term passing additionally uses lemma 102.6 to move M into the residual classifier. A reduction under parallel composition or restriction rebuilds the induction hypothesis with the same linear split. Structural congruence uses exchange, alpha-renaming, and the fact that restriction extrusion preserves the disjointness side condition. The persistent cut case invokes contraction only in Γ, never in Δ. These cases cover the operational rules of definition 102.2, so the induction proves preservation for the displayed calculus. ◻

Theorem 102.9 — Closed global progress

If ;;P::x:1andlive(P), then there is a process Q such that PQ. Here live(P) means that, up to restrictions and structural congruence, P contains a nonreplicated prefix, a forwarding process, or a term substitution.

Proof of Theorem 102.9 — Closed global progress

Proof. We first prove the contextual claim used by the closed theorem. If Ψ;Γ;ΔR::z:C and live(R), then at least one of the following conclusions is derivable up to structural congruence:

  1. RR for some process R;

  2. R exposes a prefix whose subject is z, a channel in Δ, or, when C=!A, a persistent channel in Γ;

  3. R is a forwarding process [xz] with xΔ, or a functional substitution [xM] whose free functional variables lie in Ψ.

Prove the claim by induction on the last typing rule. An introduction rule for ,,,&,1,, or exposes the constructor prescribed by that rule, so clause 2 holds. A forwarding or functional-substitution rule gives clause 3. Exchange and alpha-renaming preserve the selected clause because they change neither a prefix subject nor the free-channel set.

It remains to check the two cut families. Write the cut as (νx)(R1R2), with disjoint linear contexts in its two premises. Apply the induction hypothesis to every live premise. If one premise reduces, compatible closure reduces the cut. If the two premises expose dual actions on x, the corresponding root rule in definition 102.2 reduces the cut. This includes channel passing, label selection, termination, and the two dependent-quantifier cases. In a dependent communication, the residual classifiers are equal by lemma 102.5; functional payload communication also uses lemma 102.6. If no exposed action has subject x, restriction hides x and the remaining exposed action has a free subject belonging to the conclusion context. A forwarding or functional-substitution form at x contracts by the appropriate cut root; one on a different subject survives restriction and gives clause 3. A persistent cut uses the same analysis, except that contraction occurs only in Γ. These cases exhaust the typing rules and prove the contextual claim.

Apply the claim to the theorem’s derivation. The assumed-channel contexts Γ and Δ are empty, so clauses 2 and 3 cannot mention an assumed channel or a free functional payload. The offered channel has type 1; its only introduction is the inactive termination process, which contradicts live(P). Thus clause 2 is impossible on the offered channel as well. Clause 3 is impossible in the empty contexts. Clause 1 remains, and supplies Q with PQ. ◻

The theorem does not apply to an open process waiting on an environment, to an ill-formed functional index, or to a multiparty network with incompatible global projections. It proves neither asynchronous queue safety nor a QTT resource bound.

Exercise 102.3

★★☆ Construct a live, well-typed open process that waits for input on one linear environment channel. Show why each premise except closedness matches theorem 102.9, and why the process need not reduce alone.

Recursion and choice are a second signature

The array transfer of section 102.2 sends one vector. A provider that sends n separate elements, where n is the numeral it has just transmitted, cannot be written at all in definition 102.1: the grammar of session types is finite and has no recursion, and and & choose between two fixed continuations rather than between continuations selected by an index. Neither gap is an oversight in the presentation. Definition 102.1 is the complete set of connectives of the selected calculus, so both features require a different signature, and every theorem must be reproved there.

One such signature places the protocol itself in a static sort stype of the indexed functional language, so that a session type is a static term and index-level computation can build it.

Definition 102.10 — Static protocol terms

Extend the base sorts of the indexed functional language by a sort stype. The complete static lambda-calculus grammar used here is b0::=intbooltypevtypestype,σ::=b0σ1σ2,s::=ac(s1,,sk)λa:σ.ss1(s2). Static typing is the simply typed lambda calculus over a signature of sorted constants. Its constants of result sort stype generate protocols π::=end(i)msg(i,τ^)::πbranch(i,π1,π2)ite(b,π1,π2)quan(i,λa:σ.π)fix(λa:stype.π), where i names one of the two parties, τ^ is a linear type, b is a static Boolean expression, and σ is a sort. A channel endpoint is classified by chan(r,π), where r is the role that reads π locally. The three constructs absent from definition 102.1 are the last three: ite selects a continuation from a static Boolean, quan is the common form of the two quantifiers, and fix takes the fixed point of a static function on protocols. Thus fix in this grammar has argument sort (stypestype); it does not accept a function of sort intstype.

The array example uses an explicitly separate higher-order fixed-point extension. For a sort σ, add f:σstype, a:σπ:stypes:σfixσ(λf:σstype.λa:σ.π;s):stype. Its unfolding equation is well sorted and is named Fix: (Fix)fixσ(F;s)F(λa:σ.fixσ(F;a))s,F:(σstype)σstype.

Because ite branches on an index rather than on a transmitted label, it is genuinely index-dependent choice: the two endpoints agree on which branch is taken by computing b, and no selection message is sent. Ordinary label choice is the special case branch(i,π1,π2), which ite can encode.

The array protocol is now expressible. Write repeat(τ,n):=ite(n>0, msg(S,τ)::repeat(τ,n1), end(S)),array(τ):=quan(S, λn:int.msg(S,int(n))::repeat(τ,n)), where repeat abbreviates the higher-order fixed point fixint(λp:intstype.λn:int.ite(n>0,msg(S,τ)::p(n1),end(S)); n). Here the body has sort stype under p:intstype and n:int, so the formation rule above applies. The parameter n is supplied after the fixed point is tied; it is not passed to the unary stypestype constructor of the core grammar. Read array(τ) as: the sender chooses n, sends an integer of the singleton type int(n), and then sends exactly n elements of type τ. Unfold it at n=2: repeat(τ,2)=Fixmsg(S,τ)::repeat(τ,1)=Fixmsg(S,τ)::msg(S,τ)::repeat(τ,0)=Fixmsg(S,τ)::msg(S,τ)::end(S). Each step evaluates the static Boolean n>0 and only then selects a branch; the recursion terminates because the index decreases and ite reaches its second branch at 0. This is the exact sense in which the recursion is data-indexed: the protocol’s length is the transmitted numeral.

Exercise 102.4

★★☆ Unfold array(τ) at n=3 and write the resulting finite protocol. Then evaluate repeat(τ,n) with the guard n>0 replaced by n0 over the integers, and identify the first index at which the unfolding stops terminating.

Three deltas separate the two systems, and none of them is cosmetic. The logical calculus types proof terms in Ψ and composes processes by Cut; ATS elaborates statics and linear views into a programming-language core and discharges index constraints with an external solver. The logical calculus has no ite, no fix, and no roles; the static language has no cut rule, so it has no cut-elimination argument to carry preservation. Consequently theorem 102.8, theorem 102.9 say nothing about definition 102.10. In particular, the logical theorems do not hold for recursive or index-chosen protocols without a separate ATS metatheory.

Suggested first pass.

None of these problems is a prerequisite for a later chapter. Begin with exercise 102.5, then complete exercise 102.8.

Exercise 102.5

★★☆ Reconstruct preservation for an existential communication. Give the fresh functional variable, both substituted classifiers, and the channel-context split before and after reduction.

Exercise 102.6

★★☆ For the negative input vector-length-mismatch, calculate the rejection verdict of the finite trace checker specified in the seminar tutorial. Then locate the single premise of R that fails for that trace, and give the functional typing judgment that the premise demands and the one that actually holds. Finally, state what the run does not establish: name one hypothesis of theorem 102.8 that no finite trace check can verify.

Exercise 102.7

★★★ Define a protocol whose sender transmits n:Nat, a proof of n>0, and then an element of Fin(n). Derive a valid trace and a trace rejected because the proof and index refer to different numerals. Explain why proof irrelevance is an additional system delta.

Exercise 102.8

★★★ Practical project.dependent-session-trace-checker Implement in Kappa a finite protocol checker for dependent send, dependent receive, termination, natural-number indices, vectors, and the index-driven unfolding of repeat from section 102.5. Maintain the invariants that endpoint polarity is dual, that each endpoint advances once per communication, and that unfolding repeat(τ,n) emits exactly n messages. The named acceptance cases are vector-2  accepted: end,vector-length-mismatch  rejected: expected Vec 2,duplicate-endpoint  rejected: endpoint reused,array-3  accepted: end,array-3-short  rejected: expected Vec 1. A mutation that omits payload substitution must fail the mismatch oracle, and a mutation that unfolds repeat one step too few must fail array-3. The checker is an executable fragment; it decides finite traces and proves neither preservation nor closed global progress.

Sources. The logical calculus, bank example, reduction rules, preservation, and global progress are reconstructed from Toninho, Caires, and Pfenning’s technical report; its Figure 1 on printed p. 18 collects the rules of definition 102.1, linear implication is its Section 2.2, type preservation is its Theorem 3.3 on printed p. 19, and contextual progress and global progress are its Lemma 3.4 and Theorem 3.5 on printed pp. 19–20 [TCP11]. The static protocol sort, index-dependent choice, the fixed-point constructor, and the array protocol of section 102.5 are Wu and Xi’s Figure 6 and Example 8, together with the surface examples reported by Wu and Xi [WX17]. The retrospective supplies historical context, not an additional theorem [TCP21].

Search the book

Type to search the local edition.