Lectures onType Theory
Erasure, dependent protocols, effects, specifications, and partiality
appendix sectionrules

Erasure, dependent protocols, effects, specifications, and partiality

Graded erasure and extraction

Usage is a judgment independent of typing. Its function fragment is

eixi
U-Var
γ,pt
γλpt
U-Lam
γtδu
γ+pδtpu
U-App

Natural-number elimination uses

γzzγs,p,rsγnnδ,qA
nrp,r(γz,γs,γn)natrecp,rq(A;z;s;n)
U-Natrec

Simultaneous substitution replaces a usage row by matrix multiplication: if every row eiΨ resources σ(i), then γt entails γΨt[σ]. The natural-recursion demand is nrp,r(qz,qs,qn), governed by the five scalar laws qn0nrp,r(qz,qs,qn)qz,nrp,r(qz,qs,qn)qs+pqn+rnrp,r(qz,qs,qn),qzqz, qsqs, qnqnnrp,r(qz,qs,qn)nrp,r(qz,qs,qn),nrp,r(qz,qs,qn)qnrp,r(qzq,qsq,qnq),nrp,r(qz,qs,qn)+nrp,r(qz,qs,qn)nrp,r(qz+qz,qs+qs,qn+qn). The first three lines are NR-Base, NR-Step, and NR-Mono. The last two are NR-Right and NR-Interchange. All five lift pointwise to usage contexts. At nonzero grade, extraction retains lambdas and applications. At grade zero it uses (λ0t)=t[/x],(t0u)=t. An erased weak-pair match is admitted only at the match grades selected by Prodrec; the open-context restriction in theorem 101.11 remains a theorem hypothesis.

Dependent session quantifiers

For a total functional judgment ΨM:τ, the four added rules are

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

and

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

A functional value can also cross the process boundary through

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

A principal quantifier cut substitutes the communicated functional term in the receiving continuation. Functional substitution changes all protocol indices; linear channel substitution composes processes and requires a disjoint split of the linear channel context.

Dependent call-by-push-value

The value/computation boundary has

ΓvV:A
ΓcreturnV:FA
Return
ΓcM:B
ΓvthunkM:UB
Thunk
ΓvV:UB
ΓcforceV:B
Force

The dependent Kleisli extension is preceded by the nondependent sequencing rule

ΓcM:FAΓ,x:AcN:BxFV(B)
ΓcMtoxinN:B
Bind^-

The plus rule is

Γ,z:UFA,ΓB ctypeΓcM:FAΓ,x:A,Γ[trx/z]cN:B[trx/z]
Γ,Γ[thunkM/z]cMtoxinN:B[thunkM/z]
Bind^+

where trx=thunk(returnx). Its beta root is (returnV)toxinN0N[V/x]. A step of M is type preserving at this rule only when the classifier has the printed thunkability equation.

Dijkstra computation types

The generated state transformer operations are returnStwp(a)(p)(s)=p(a,s),bindStwp(w,k)(p)(s0)=w(λ(a,s1).k(a)(p)(s1))(s0),getwp(p)(s)=p(s,s),putwp(s)(p)(s)=p(unit,s). For state with exceptions, the distinctive failure and handler clauses are raiseStExnwp(e)(p)(q)(s)=q(e,s),bindStExnwp(w,k)(p)(q)(s0)=w(λ(a,s1).k(a)(p)(q)(s1))(q)(s0),catchStExnwp(w,h)(p)(q)(s0)=w(p)(λ(e,s1).h(e)(p)(q)(s1))(s0). Computation types use generated transformers through

ΓV:A
ΓreturnV:MA(returnwpV)
WP-Return
ΓM:MAwΓ,x:AN:MBk(x)
ΓMtoxinN:MB(bindwp(w,k))
WP-Bind

and weakening a specification uses

ΓM:MAwΓp.w(p)w(p)
ΓM:MAw
WP-Sub

Partial elements

For Aν, convergence and guarded sequencing are generated by

aa
Conv-Return
xa
xa
Conv-Step

a=f=f(a),(x)=f=(x=f). Weak equality and the approximation order are x=νy:=a.xaya,fg:=a,b.f(a)bg(a)b. The monad laws hold at =ν, not at raw constructor equality.

Graded erasure: additional formation, equality, usage, and dynamics

Together with the graded-erasure card immediately above, the rules below record the noninherited part of the signature in definition 101.2, definition 101.3, definition 101.4,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U-Sub
Γtu:AΓA=B
Γtu:B
R-Conv
Γ.ABΓ.At:BΓu:A
Γ(λpt)put[u]:B[u]
R-β
Γ.ABΓtt:Σ&qAB
Γfsttfstt:A
R-Fst
Γ.ABΓt:AΓu:B[t]
Γfst(t,u)&t:A
R-Fst-β
Γ.ABΓtt:Σ&qAB
Γsndtsndt:B[fstt]
R-Snd
Γ.ABΓt:AΓu:B[t]
Γsnd(t,u)&u:B[fst(t,u)&]
R-Snd-β
Γtt:ΣqABΓ.ΣqABCΓ.A.Bu:C[2,(x1,x0)]
Γprodrecrq(C;t;u)prodrecrq(C;t;u):C[t]
R-Prodrec
Γ.ΣqABCΓt1:AΓt2:B[t1]Γ.A.Bu:C[2,(x1,x0)]
Γprodrecrq(C;(t1,t2);u)u[t1,t2]:C[(t1,t2)]
R-Prodrec-β
Γnn:NΓz:A[zero]Γ.N.As:A[2,sucx1]
Γnatrecp,rq(A;z;s;n)natrecp,rq(A;z;s;n):A[n]
R-Natrec
Γz:A[zero]Γ.N.As:A[2,sucx1]
Γnatrecp,rq(A;z;s;zero)z:A[zero]
R-Nat-Zero
Γz:A[zero]Γ.N.As:A[2,sucx1]Γn:N
Γnatrecp,rq(A;z;s;sucn)s[n,natrecp,rq(A;z;s;n)]:A[sucn]
R-Nat-Suc
ΓAΓtt:
Γemptyrecp(A;t)emptyrecp(A;t):A
R-Emptyrec
(λv)wv[w]
E-β
vv
vwvw
E-App
vv
fstvfstv
E-Fst
fst(v,w)v
E-Fst-β
snd(v,w)w
E-Snd-β
vv
sndvsndv
E-Snd
vv
prodrec(v;w)prodrec(v;w)
E-Prodrec
prodrec((v,v);w)w[v,v]
E-Prodrec-β
natrec(z;s;zero)z
E-Nat-Zero
vv
natrec(z;s;v)natrec(z;s;v)
E-Natrec
natrec(z;s;sucv)s[v,natrec(z;s;v)]
E-Nat-Suc

Dependent sessions: additional base-rule delta

The quantifier and functional-passing rules are printed in the dependent session card above. The propositions-as-sessions rules are inherited from subappendix A.61; the seven rules below are the additional base rules used by definition 102.1. Thus every omitted rule has one named earlier card rather than an implicit premise.

Ψ;Γ;0::z:1
Ψ;Γ;ΔP::z:C
Ψ;Γ;Δ,x:1P::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::y:A
Ψ;Γ;!z(y).P::z:!A
!R
Ψ;Γ,u:A;ΔP::z:C
Ψ;Γ;Δ,x:!AP[x/u]::z:C
!L
Ψ;Γ;P::x:AΨ;Γ,u:A;ΔQ::z:C
Ψ;Γ;Δ(νu)((!u(x).P)Q)::z:C
Cut^!

Dependent effects: additional operation and inclusion delta

The value/computation boundary and both bind rules are printed in the card above. The following rules supplement the point-of-use operation, stack, and machine signatures in definition 103.4, definition 103.8. Those definitions display the complete transition relation; this card does not duplicate every constructor-preserving machine frame.

Γ,x:BA:UΓ:A[true/x]Γ:A[false/x]
Γ,x:B:A
Dep- B-E
ΓcdivergeB:B
Diverge
Γ,z:UBcM:B
ΓcμzBM:B
Rec
ΓcerrorBe:B
Error
ΓcM:B
Γcprintm.M:B
Print
{ΓcMi:B}1in
Γcchoosei(Mi):B
Choose
Γ;Cknil:C
Nil
ΓvV:AΓ;B[V/x]kK:C
Γ;Πx:ABkV::K:C
Arg
ΓcN:B[thunkM/z]
ΓcN:B[thunk(writes.M)/z]
Incl-Write
ΓcN:B[thunkMs/z]
ΓcN:B[thunk(readtos(Ms))/z]
Incl-Read
ΓcN:B[thunkM/z]
ΓcN:B[thunk(printm.M)/z]
Incl-Print
ΓcN:B[thunkMi/z]
ΓcN:B[thunk(choosei(Mi))/z]
Incl-Choose

Weakest preconditions: execution rules

The transformer equations and WP-Return, WP-Bind, and WP-Sub are printed in the preceding card. These are the two additional execution rules of definition 104.6.

Γe:PureAwΓp.w(p)
Γrune:TotA
WP-Run
run(Pure.returnv)v
R-Run

Dependent subtyping: additional algorithmic rule delta

The declarative product, refinement, and cast rules are printed in the card above. The following formation and bidirectional rules form the algorithmic delta of definition 106.1, definition 106.4; the complete rule families remain displayed at those definitions.

ΓA:UΓ,x:AB:U
ΓΠx:AB:U
Π-F
Γ,x:AM:B
Γλx:A.M:Πx:AB
Π-I
ΓF:Πx:ABΓN:A
ΓFN:B[N/x]
Π-E
fv(ϕ)dom(Γ){ν}Γvertices(ϕ)well-sorted
ΓDRef{ν:Bϕ}type
R-Base-F
ΓDRefRtypeΓ,x:RDRefStype
ΓDRefΠx:RStype
R-Π-F
ΓDRefm[m]Int
A-Int
ΓDRefRtypeΓ,x:RDRefeS
ΓDRefλx:R.eΠx:RS
A-Lam
ΓDRefeΠx:RSΓDRefvR
ΓDRefevS[v/x]
A-App
ΓDRefeRΓDRefR<:S
ΓDRefeS
A-Check

Dependent object types: additional structural rule delta

The selection, recursive-self, field, and tight-member rules are printed in the object-type card above. The following structural and definition rules supplement the complete point-of-use family in definition 107.2; this card does not duplicate its application, let, and evaluation-context schemas.

ΓT<:
DOT-Top
Γ<:T
DOT-Bot
ΓT<:T
DOT-Refl
ΓS<:TΓT<:U
ΓS<:U
DOT-Trans
ΓTU<:T
DOT-And_1-
ΓTU<:U
DOT-And_2-
ΓS<:TΓS<:U
ΓS<:TU
DOT–And
ΓT<:U
Γ{a:T}<:{a:U}
DOT-Fld–Fld
Γ,x:Td:T
Γν(x:T)d:μ(x:T)
DOT-Obj-I
Γt:T
Γ{a=t}:{a:T}
DOT-Def-Val
Γd1:T1Γd2:T2dom(d1)dom(d2)=
Γd1d2:T1T2
DOT-Def-And

Fully path-dependent types: additional replacement and lookup delta

The stable-path, singleton, replacement-leaf, and nested-initialization rules are printed in the pDOT card above. The following rules complete the named replacement descent and lookup deltas; all unchanged DOT rules are inherited from definition 107.2.

Γqpath
p;Γ{a=q}:{a:q.type}
Def-Path
ΓReplace(S,p,q,S)
ΓReplace({a:S},p,q,{a:S})
R-Fld
ΓReplace(S,p,q,S)
ΓReplace({A:S..U},p,q,{A:S..U})
R-Mem-L
ΓReplace(U,p,q,U)
ΓReplace({A:S..U},p,q,{A:S..U})
R-Mem-U
ΓReplace(S,p,q,S)
ΓReplace(SU,p,q,SU)
R-And-L
ΓReplace(U,p,q,U)
ΓReplace(SU,p,q,SU)
R-And-R
ΓReplace(S,p,q,S)Γ,x:SUtype
ΓReplace((x:S)U,p,q,(x:S)U)
R-All-Dom
Γ,x:SReplace(U,p,q,U)xfv(p)fv(q)
ΓReplace((x:S)U,p,q,(x:S)U)
R-All-Cod
Γ,x:μ(x:T)Replace(T,p,q,T)Γμ(x:T)typexfv(p)fv(q)
ΓReplace(μ(x:T),p,q,μ(x:T))
R-Rec
γ(x)=v
Lookupγ(x)=v
Lookup-Var
Lookupγ(p)=ν(z:T)(d1{a=s}d2)
Lookupγ(p.a)=s[p/z]
Lookup-Val
Lookupγ(p)=q
Lookupγ(p.a)=q.a
Lookup-Path

Proof-dependent classical control: additional dependent rule delta

The cut, control, dependent-product, NEF, and dependency-list rules are printed in the classical-control card above. The following rules form the distinctive delta of definition 109.1, definition 109.4; the ordinary positive and equality schemas remain at those point-of-use definitions.

Γt:NΓp:A[t/x]Δ
Γ(t,p):x:N.AΔ
-R
Γp:x:N.AΔpD
Γwit(p):N
Wit
Γp:x:N.AΔpD
Γprf(p):A[wit(p)/x]Δ
Prf
BAσ
Γtp^:AdΔ,tp^:B;σ{p}
tp
c:(Γ,a:AdΔ,tp^:B;σ{ap})
Γμ~a.c:AdΔ,tp^:B;σ{p}
μ-d
Γabortα:α:P,Δ
-L

Search the book

Type to search the local edition.