Lectures onType Theory
Effect capabilities, explicit labels, and tunnelling
appendix sectionrules

Effect capabilities, explicit labels, and tunnelling

This appendix freezes the three independent calculi used by chapter 32. Identical letters in different cards do not identify judgments across cards.

System Xi

The selected source and runtime syntax is τ::=IntBool1,σ::=(τ¯,σ¯)τ,e::=xv,v::=()ntruefalse,b::=fu,u::=wcap{(x,k)s},w::={(x¯:τ¯,f¯:σ¯)s},s::=eval x=s;sdef f=b;sb(e¯,b¯)handle{Fs}with{(x,k)s}#{s}. The contexts and judgments are Γ::=Γ,x:τ,Δ::=Δ,f:σ,Ξ::=Ξ,:τ,Γe:τ,ΓΔΞb:σ,ΓΔΞs:τ. All judgments are relative to a fixed operation signature Ω, with Ω(F)=τ1τ0. This arrow abbreviates the single-value, no-block-parameter type ((τ1),())τ0; block-context lookup is rightmost. The selected pure fragment contains exactly unit, integer and Boolean constants and variables; its constant signature is C(())=1, C(n)=Int, and C(true)=C(false)=Bool. Value types contain no block type. Expressions contain no block variable or block abstraction. This syntactic separation is the second-class restriction.

The complete selected typing rules are

x:τΓ
Γx:τ
X-Var
C(v)=τ
Γv:τ
X-Const
Δ(f)=σ
ΓΔΞf:σ
X-BVar
Γ,x¯:τ¯Δ,f¯:σ¯Ξs:τ
ΓΔΞ{(x¯:τ¯,f¯:σ¯)s}:(τ¯,σ¯)τ
X-Block
Γe:τ
ΓΔΞe:τ
X-Expr
ΓΔΞs0:τ0Γ,x:τ0ΔΞs1:τ1
ΓΔΞval x=s0;s1:τ1
X-Val
ΓΔΞb:σΓΔ,f:σΞs:τ
ΓΔΞdef f=b;s:τ
X-Def
ΓΔΞb:(τ¯,σ¯)τ0(Γei:τi)i(ΓΔΞbj:σj)j
ΓΔΞb(e¯,b¯):τ0
X-Call
Ω(F)=τ1τ0ΓΔ,F:τ1τ0Ξs:τΓ,x:τ1Δ,k:τ0τΞsh:τ
ΓΔΞhandle{Fs}with{(x,k)sh}:τ
X-Handle
Ξ=Ξ0,:τ,Ξ+Γ,x:τ1Δ,k:τ0τΞ0sh:τ
ΓΔΞcap{(x,k)sh}:τ1τ0
X-Cap
dom(Ξ)ΓΔΞ,:τs:τ
ΓΔΞ#{s}:τ
X-Delim

The ordered label context records allocation origin. In Ξ0,:τ,Ξ+, the stored handler body is typed in the birth prefix Ξ0; Ξ+ contains only delimiters allocated after . This exact prefix premise, rather than deletion from an unordered set, is what preserves the clause type when a request crosses intervening delimiters.

Evaluation contexts and contexts not binding are H::=[]val x=H;s#{H},H::=[]val x=H;s#{H}(). Reduction is compatible closure under H of val x=v;s0s[v/x]XValbeta,def f=u;s0s[u/f]XDefbeta,{(x¯,f¯)s}(v¯,u¯)0s[v¯/x¯][u¯/f¯]XBlockbeta,#{v}0vXDelimret. Handler allocation is handle{Fs}with{(x,k)sh}0#{s[cap{(x,k)sh}/F]}XHandlebeta. The remaining root contraction captures the delimited context: #{H[cap{(x,k)sh}(v)]}0sh[v/x,{(y:τ0)#{H[y]}}/k]XCapbeta. The label chosen by X-Handle-beta is fresh. Source terms contain no labels; runtime typing extends Ξ only through X-Delim.

Effekt

The selected Effekt source is τ::=IntBool1,σ::=(τ¯,σ¯)τ/ε,ε::={F1,,Fn},v::=()ntruefalse,e::=xv,s::=eval x=s;sdef f(x¯:τ¯,g¯:σ¯):τ/ε=s;sf(e¯,g¯)effect F(x:τ1):τ0;sdo F(e)try{s}with F{(x:τ1)sh}. The judgments are Γe:τ and ΓΔΣs:τε, where Σ(F)=τ1τ0. Value variables, ordinary block variables, and operation names are pairwise disjoint syntactic classes; binders are alpha-renamed before extension. Expressions use X-Var and X-Const. The complete statement rules are

Γe:τ
ΓΔΣe:τ
E-Expr
ΓΔΣs0:τ0ε0Γ,x:τ0ΔΣs1:τ1ε1
ΓΔΣval x=s0;s1:τ1ε0ε1
E-Val
Γ,x¯:τ¯Δ,g¯:σ¯Σs0:τ0ε0ΓΔ,f:(τ¯,σ¯)τ0/ε0Σs:τε
ΓΔΣdef f(x¯:τ¯,g¯:σ¯):τ0/ε0=s0;s:τ(ε0ε0)ε
E-Def
Δ(f)=(τ¯,σ¯)τ/ε(Γei:τi)i(Δ(gj)=σj)j
ΓΔΣf(e¯,g¯):τε
E-Call
ΓΔΣ,F:τ1τ0s:τεFε
ΓΔΣeffect F(x:τ1):τ0;s:τε
E-Effect
Σ(F)=τ1τ0Γe:τ1
ΓΔΣdo F(e):τ0{F}
E-Do
Σ(F)=τ1τ0ΓΔΣs:τεΓ,x:τ1Δ,resume:τ0τ/Σsh:τεh
ΓΔΣtry{s}with F{(x:τ1)sh}:τ(ε{F})εh
E-Try

Effekt has no separate direct reduction relation in this chapter. Its semantics is the named syntax translation of Appendix D followed by System Xi reduction.

The tunnelling calculus

The selected syntax is e::=αh.lbl,T,S::=1IntS[T]e¯α.TΠh:F.[T]e¯,h,g::=hvH,H::=handlerFx k.t,t::=()nxλx:T.tttlet x:T=t in tΛα.tt[e¯]λh:F.tthh[T]e¯t. Here hv is an atomic handler variable; binders use h as its metavariable. This repairs the self-referential production printed in the source. The source core has only unit; this book adds Int, integer literals, and the three formation rules below for the chapter’s observable examples. Contexts are Δ for effect variables, P for handler variables, Γ for term variables, and Ξ for labels. The four judgments are ΔPΞT type,ΔPΞe¯ effects,ΔPΓΞt:[T]e¯,ΔPΓΞh:Fe. They are relative to a fixed interface signature O; the premise op(F)=TS abbreviates O(F)=TS, and TS abbreviates T[S]. Effect sequences are identified up to permutation, duplicate removal, and flattening under effect substitution. The four characteristic rules are printed in Figure 10 of the source paper. The formation, ordinary typing, subtyping, and effect-inclusion rules below are the exact closure printed in Appendix A.1 of Cornell technical report 1813/60202. In particular, application and let assign one common effect to their premises; union-effect forms are derived with T-Sub, not substituted for the published rules. The complete table begins with well-formedness:

ΔPΞ effects
WF-Emp
αΔ
ΔPΞα effects
WF-EVar
dom(Ξ)
ΔPΞ effects
WF-Label
P(h)=F
ΔPΞh.lbl effects
WF-HLabel
ΔPΞe¯1 effectsΔPΞe¯2 effects
ΔPΞe¯1,e¯2 effects
WF-ESeq
ΔPΞ1 type
WF-Unit
ΔPΞInt type
WF-Int
ΔPΞS typeΔPΞT typeΔPΞe¯ effects
ΔPΞS[T]e¯ type
WF-Fun
Δ,αPΞT type
ΔPΞα.T type
WF-EAll
ΔP,h:FΞT typeΔP,h:FΞe¯ effects
ΔPΞΠh:F.[T]e¯ type
WF-HAll

The term and handler rules are

ΔPΓΞ():[1]
T-Unit
ΔPΓΞn:[Int]
T-Int
x:TΓ
ΔPΓΞx:[T]
T-Var
ΔPΞS typeΔPΓ,x:SΞt:[T]e¯
ΔPΓΞλx:S.t:[S[T]e¯]
T-Lam
ΔPΓΞt1:[S[T]e¯]e¯ΔPΓΞt2:[S]e¯
ΔPΓΞt1t2:[T]e¯
T-App
ΔPΞS typeΔPΓΞt1:[S]e¯ΔPΓ,x:SΞt2:[T]e¯
ΔPΓΞlet x:S=t1 in t2:[T]e¯
T-Let

Type subtyping is the least transitive relation generated by

ΔPΞ11
S-Unit
ΔPΞIntInt
S-Int
ΔPΞT2T1ΔPΞS1S2ΔPΞe¯1e¯2
ΔPΞT1[S1]e¯1T2[S2]e¯2
S-Fun
Δ,αPΞT1T2
ΔPΞα.T1α.T2
S-AllE
ΔP,h:FΞT1T2ΔP,h:FΞe¯1e¯2
ΔPΞΠh:F.[T1]e¯1Πh:F.[T2]e¯2
S-AllH
ΔPΞT1T2ΔPΞT2T3
ΔPΞT1T3
S-Trans

Effect inclusion and term subsumption are

(j)(i). e1j=e2i(ΔPΞe2i effects)i
ΔPΞe¯1e¯2
Eff-Sub
ΔPΓΞt:[T1]e¯1ΔPΞT1T2ΔPΞe¯1e¯2
ΔPΓΞt:[T2]e¯2
T-Sub

The usual union-effect application and sequencing rules are admissible by subsuming their premises to a common finite join before applying T-App or T-Let.

Δ,αPΓΞt:[T]
ΔPΓΞΛα.t:[α.T]
T-EAbs
ΔPΓΞt:[α.T]e¯0ΔPΞe¯ effects
ΔPΓΞt[e¯]:[T[e¯/α]]e¯0
T-EApp
ΔP,h:FΓΞt:[T]e¯
ΔPΓΞλh:F.t:[Πh:F.[T]e¯]
T-HAbs
ΔPΓΞt:[Πh:F.[T]e¯]e¯0ΔPΓΞh:Fe
ΔPΓΞth:[T[h]]e¯[h],e¯0
T-HApp
P(h)=F
ΔPΓΞh:Fh.lbl
T-HVar
ΔPΓΞh:Feop(F)=TS
ΔPΓΞh:[T[S]e]
T-Up
Ξ()=[S]e¯op(F)=T1T2ΔPΓ,x:T1,k:T2[S]e¯Ξt:[S]e¯
ΔPΓΞ(handlerFx k.t):F
T-HDef
dom(Ξ)ΔPΓΞ,:[T]e¯t:[T]e¯,ΔPΞT typeΔPΞe¯ effects
ΔPΓΞ[T]e¯t:[T]e¯
T-Down

Here T[h] and e¯[h] replace the bound handler variable by its argument and replace h.lbl by the argument label. Every context extension in this card binds a fresh name; the explicit first premise of T-Down records the delimiter-label instance of that convention. Since the type and effect well-formedness premises are checked before the fresh label is added, WF-Label derives fl(T,e¯); this is not an independent hypothesis.

Values and evaluation contexts are v::=()λx:T.tΛα.tλh:F.tH,K::=[]KtvKK[¯]KHlet x:T=K in tK. Contextual refinement quantifies over the larger program-context grammar C::=[]C[λx:T.[]]C[[]t]C[t[]]C[let x:T=[] in t]C[let x:T=t in []]C[Λα.[]]C[[][e¯]]C[λh:F.[]]C[[]h]C[t(handlerFx k.[])]C[(handlerFx k.[])]C[[T]e¯[]]. Its well-formedness judgment is C:ΔPΓΞ[T]e¯T. These are not the evaluation contexts K. Reduction is compatible closure under K of (λx:T.t)v0t[v/x]TunAppbeta,(Λα.t)[¯]0t[¯/α]TunEffbeta,(λh:F.t)H0t[H/h]TunHandlerbeta,let x:T=v in t0t[v/x]TunLetbeta,v0vTunDownval. The tunneled request contraction is K[Hv]0t[v/x,(λy:T2.K[y])/k]TunDownup. where H=handlerFx k.t, op(F)=T1T2, and K does not bind .

Source-bounded finer cards

Control-flow linearity uses the comparison predicate uses(r,M)q, q{1,ω}, from section 32.5; no rule of the source calculus is imported.

The Olaf source boundary uses the typing judgment ΔΘΓΞt:[τ]c and configuration transition L;tL;t. Its operation signatures, continuation types, lifetime effects, fixpoint handlers, and rules belong to the source calculus of [ZSM20]; section 32.5 records its theorem boundary. No Olaf rule is imported into System Xi, Effekt, or the tunnelling calculus.

The locality source card distinguishes ordinary bindings Γ;x:τ from global bindings Γ;x:τ and restricts contexts by /=,(Γ;x:τ)/=Γ/,(Γ;x:τ)/=(Γ/);x:τ. Its characteristic introduction rule is

Γ/Vv:τ
ΓVbox v:τ
Loc-Box

The effect-reflection card uses y(Σ), WΣ(τ), reflect, and reifyΣ with

ΓVv1:y(Σ)op:τ1τ2ΣΓVv2:τ1Γ;x:τ2Cc:τ3
ΓCreflect(v1(op))(v2,x.c):τ3
Refl-Up
Γ;x:y(Σ)Cc:τ
ΓCreifyΣ(x.c):WΣ(τ)
Refl-Down

These two cards belong to [Whi26]; they supply no rule to the three principal calculi of this appendix section.

Search the book

Type to search the local edition.