Lectures onType Theory
Modal effects and the two source cards
appendix sectionrules

Modal effects and the two source cards

This appendix freezes the selected rules used by chapter 33. Identical metavariables in the three cards do not identify their judgments.

Met[T]

Fix an effect structure T, a signature Σ()=AB, and the modality action and composition from section 33.1. Write L(Γ) for the composite of locks in Γ. Kinds are Abs, Any, and Eff, with Abs the sole proper subkind of Any. The effect structure supplies extension kinding ΓD:Eff and equivalence ΓDTD. The induced effect-context interface is

Γ:Eff
E-Empty
ϵ:EffΓ
Γϵ:Eff
E-Var
ΓD:EffΓE:Eff
ΓD,E:Eff
E-Cons
ΓT
E-EqEmpty
ϵ:EffΓ
ΓϵTϵ
E-EqVar
ΓD1TD2ΓE1TE2
ΓD1,E1TD2,E2
E-EqCons
ΓE,DTF
ΓEeF
E-Include

Variables have their declared kind; 1:Abs; [E]A:Abs when A:Any; DA:K when A:K; arrows have kind Any; and αK.A:K when Γ,α:KA:K. Each operation declaration AB requires A,B:Abs.

For completeness, the value-type kinding rules are

ΓA:Abs
ΓA:Any
K-Sub
α:KΓ
Γα:K
K-Var
Γ1:Abs
K-Unit
Γ[E]ΓA:Any
Γ[E]A:Abs
K-AbsBox
ΓDΓA:K
ΓDA:K
K-ExtBox
ΓA:AnyΓB:Any
ΓAB:Any
K-Arrow
Γ,α:KA:K
ΓαK.A:K
K-Forall
ΓE:Eff
Γ[E]
K-AbsMod
ΓD:Eff
ΓD
K-ExtMod
ΓA:AbsΓB:Abs
ΓAB
K-OpSig

Figure 9, Appendix B.1, p. 31 of [TL26] reuses K for both the quantified variable and the body kind in K-Forall. That printing rejects the paper’s own effect-polymorphic capability translation. Rule K-Forall above makes the necessary distinction between binder kind K and body kind K.

Modal and type equivalence are structural over the selected effect equivalence:

ΓETF
Γ[E]Met[F]
Eq-AbsMod
ΓDTD
ΓDMetD
Eq-ExtMod
α:KΓ
ΓαMetα
Eq-Var
Γ1Met1
Eq-Unit
ΓμMetνΓAMetB
ΓμAMetνB
Eq-Box
ΓAMetAΓBMetB
ΓABMetAB
Eq-Arrow
Γ,α:KAMetB
ΓαK.AMetαK.B
Eq-Forall

The context well-formedness judgment is Γ@E. Its full rules are

@E
WF-Empty
Γ@FΓA:K
Γ,x:μFA@F
WF-Var
Γ@Fμ(F)=E
Γ,lock(μF)@E
WF-Lock
Γ@E
Γ,α:K@E
WF-TVar
Γ@EΓAB
Γ,:AB@E
WF-Label

The effect-structure kinding rules and the following term rules complete the frozen target signature.

Γ():1@E
M-Unit
Γ,x:AM:B@E
ΓλxA.M:AB@E
M-Abs
ΓM:AB@EΓN:A@E
ΓMN:B@E
M-App
Γ,α:KV:A@E
ΓΛαK.V:αK.A@E
M-TAbs
ΓM:αK.A@EΓB:K
ΓMB:A[B/α]@E
M-TApp

Variable access factors through a type-sensitive auxiliary transformation:

ΓA:Abs
Γ(μ,A)ν@F
M-Aux-Abs
Γμν@F
Γ(μ,A)ν@F
M-Aux-Mod
Γ(μ,A)L(Γ)@F
Γ,x:μFA,Γx:A@E
M-Var
Γ,lock(μF)V:A@μ(F)
ΓmodμV:μA@F
M-Mod
Γ,lock(νF)V:μA@ν(F)Γ,x:(νμ)FAN:B@F
Γletνmodμx=VinN:B@F
M-LetMod

Only values may be introduced or eliminated by these rules. The ordinary unit, abstraction, application, type-abstraction, and type-application rules are the call-by-value System-F rules, all at one displayed effect context. Operations and fresh local labels use

Σ,Γ:ABΓN:A@(,E)
ΓdoN:B@(,E)
M-Do
Γ,:ABM:C@E
Γlocal:ABinM:C@E
M-Local

For H={return xN,prN}, the handler rule is

μ(F)=EΓμid@FΓμμμ@FΓ,lock(μF),lock(E)M:A@(,E)Γ,lock(μF),x:idEμAN:B@EΣ()=ABΓ,lock(μF),p:A,r:μ(BB)N:B@E
ΓhandleμMwithH:B@F
M-Handle

Value normal forms and evaluation contexts are U::=()xλxA.MΛαK.VmodμU,K::=[]KMUKKAmodμKdoKletνmodμx=KinMhandleμKwithH. The unit case is the minimal repair identified in section 33.1; all other clauses reproduce source Figure 2. The complete roots are (λxA.M)U0M[U/x],(ΛαK.U)A0U[A/α],letνmodμx=modμUinN0N[U/x],local:ABinM;Ω0M[/];(Ω,:AB),handleμUwithH0N[modμU/x],handleμK[doU]withH0N[U/p,modμ(λy.handleμK[y]withH)/r]. The generated label avoids dom(Σ,Ω). The last contraction requires that K bind no handler for ; one-step reduction is the compatible closure under K.

System Fε

The kinds, rows, types, contexts, values, and computations are K::=ValueEffect,E::=ϵ,E,A::=1αAEBαK.A,Γ::=Γ,x:AΓ,α:K,V::=()xλExA.MΛαK.Vhandler H,M::=return VVWVAlet x=M in NdoV,H::={prN}. Rows preserve duplicates and are equal modulo permutation. The judgments are ΓvV:A and ΓcM:A!E. Their complete static rules are

Γv():1
F-Unit
x:AΓ
Γvx:A
F-Var
Γ,α:KvV:A
ΓvΛαK.V:αK.A
F-TAbs

Figure 11, Appendix D.1, p. 44 of [TL26] prints A, rather than αK.A, in the conclusion of its type-abstraction rule. The displayed conclusion is the minimal well-formed repair: it is the type consumed by F-TApp and by the paper’s translation clause.

Γ,x:AcM:B!E
ΓvλExA.M:AEB
F-Abs
ΓvV:AEBΓvW:A
ΓcVW:B!E
F-App
ΓvV:A
Γcreturn V:A!E
F-Return
ΓvV:αK.BΓA:K
ΓcVA:B[A/α]!E
F-TApp
ΓcM:A!EΓ,x:AcN:B!E
Γclet x=MinN:B!E
F-Let
Σ()=ABΓvV:A
ΓcdoV:B!(,E)
F-Do
Σ()=ABΓ,p:A,r:BEAcN:A!E
Γvhandler{prN}:(1,EA)EA
F-Handler

Runtime computations add handle M with H, with contexts R::=[]let x=R in Nhandle R with H. The complete roots of Figure 12, Appendix D.1, pp. 44–45 are (ΛαK.V)A0V[A/α],(λExA.M)V0M[V/x],(handler H)V0handle (V()) with H,handle (return V) with H0return V,handle R[doV] with H0N[V/p,(λEy.handle R[return y] with H)/r]. The final root requires bl(R) and (prN)H; reduction is closed under R.

System C

The exact static grammar is A::=1T@C,T::=(A¯;f¯:T¯)B,C::={f}CC,Γ::=Γ,x:AΓ,f:CTΓ,f:T,V::=x()box P,P::=f{(x¯:A¯;f¯:T¯)M}unbox V,M::=return VP(V¯;Q¯)let x=M in Ndef f=P in Ntry{fABM}with{p,rN}. System C has judgments ΓvV:A, ΓbP:TC, and ΓcM:AC. The complete static rules are

Γv():1
SC-Unit
x:AΓ
Γvx:A
SC-Var
ΓbP:TC
Γvbox P:T@C
SC-Box
f:TΓ
Γbf:T{f}
SC-Tracked
f:CTΓ
Γbf:TC
SC-Transparent
ΓvV:T@C
Γbunbox V:TC
SC-Unbox
Γ,x¯:A¯,f¯:T¯cM:BC{f¯}
Γb{(x¯;f¯)M}:(A¯;f¯:T¯)BC
SC-Block
ΓbP:TCCC
ΓbP:TC
SC-BSub
ΓvV:A
Γcreturn V:A
SC-Return
ΓbP:(A¯;f¯:T¯)BC(ΓvVi:Ai)i(ΓbQj:TjCj)j
ΓcP(V¯;Q¯):B[C¯/f¯]CjCj
SC-Call
ΓcM:ACΓ,x:AcN:BC
Γclet x=M in N:BCC
SC-Let
ΓbP:TCΓ,f:CTcN:AC
Γcdef f=P in N:AC
SC-Def
ΓcM:ACCC
ΓcM:AC
SC-Sub
Γ,f:((A)B)cM:AC{f}Γ,p:A,r:C((B)A)cN:AC
Γctry{fABM}with{p,rN}:AC
SC-Handle

These are Figure 4, §5.1, p. 21 of [TL26]. The handler premise binds f as tracked; its clause binds r transparently with the residual capability set.

Runtime syntax extends capabilities by labels: Ω::=Ω,:(A)B,C::={},P::=cap,M::=tryM with H,K::=[]let x=K in Ndef f=K in NtryK with H. For the operation root, abbreviate the reified deep resumption by resume,K,H:={(y)tryK[return y] with H}. In addition to compatible closure, the roots are unbox(box P)0P,let x=return V in N0N[V/x],def f=P in N0N[P/f],{(x¯;f¯)M}(V¯;Q¯)0M[V¯/x¯,Q¯/f¯,C¯/f¯],try{fABM}with H;Ω0tryM[cap/f,{}/f]with H;(Ω,:(A)B),try(return V) with H0return V,tryK[cap(V)]with H0N[V/p,resume,K,H/r]. Here H={p,rN}, the fourth root uses bQj:TjCj for each actual block, the generated is fresh, and the last root requires bl(K). These are Figure 13, Appendix D.2, pp. 44–45 of the same source. Block beta substitutes actual blocks in terms and their capability sets in types as two distinct simultaneous components.

The two translations are the type-directed maps in section 33.2, section 33.3. They share no source judgment and must not be composed through a presumed inverse.

Search the book

Type to search the local edition.