Lectures onType Theory
Capture, typestate, and coeffect interfaces
appendix sectionrules

Capture, typestate, and coeffect interfaces

Chapter 51: CF<:

Types are X or CU, where U::=Π(x:S).T(X<:S).T and C::={x1,,xn}. Capture-set substitution replaces x by a finite or universal bound in type annotations. The complete subcapturing generators are

ΓCcap
SC-Star
Γ{xi}capC(1in)
Γ{x1,,xn}capC
SC-Set-L
1in
Γ{xi}cap{x1,,xn}
SC-Set-R
x:TΓΓcv(T,Γ)capC
Γ{x}capC
SC-Var

Reflexivity and transitivity are admissible. Capture and function subtyping retain their two premises:

ΓC1capC2ΓU1<:U2
ΓC1U1<:C2U2
Capt
ΓS2<:S1Γ,x:S2T1<:T2
ΓΠ(x:S1).T1<:Π(x:S2).T2
Fun

The capture-specific typing interface is x:CUΓΓx:{x}UVarC. Γ,x:St:TΓΠ(x:S).TwfΓλ(x:S).t:fv(λ(x:S).t)Π(x:S).TAbsC. Variables declared at abstract type X retain type X. Type abstraction attaches its free variables, type application performs bounded substitution, and subsumption closes the typing relation:

x:XΓ
Γx:X
Var-X
Γ,X<:St:TΓ(X<:S).Twf
ΓΛ(X<:S).t:fv(Λ(X<:S).t)(X<:S).T
TAbs-C
Γt:C(X<:R).TΓS<:RΓSwf
Γt[S]:T[S/X]
TApp-C
Γt:TΓT<:S
Γt:S
Sub-C

Γt:CΠ(x:S).TΓs:SΓts:T[cv(S,Γ)/x]AppC. v value(λ(x:S).t)vcapt[fv(v)/x][v/x]BetaC. Formation tracks positive and negative occurrences of term variables in type annotations. An arrow swaps polarities in its domain and admits its binder only positively in its codomain.

The separate CC<: card uses pure types containing (CR), explicit unboxing, and monadic-normal-form machine states SEe. Its state-typing judgment combines store, continuation, and focused-expression typing. These rules do not extend the CF<: signature above.

Chapter 52: affine file typestate

The state set is {open,eof,closed}. Read branches from open to open or eof; close goes from open or eof to closed. Protocol contexts map variables to File[q] and admit no contraction. The flow judgment ΔPΔ has the following return, open, close, and read rules:

ΔreturnΔ
TS-Return
Δ,f:File[open]PΔfdom(Δ)
Δopen f;PΔ
TS-Open
q{open,eof}ΔPΔ
Δ,f:File[q]close f;PΔ
TS-Close
Δ,f:File[open]PmΔΔ,f:File[eof]PeΔ
Δ,f:File[open]read f as{more(f)Pmeof(f)Pe}Δ
TS-Read

The two read premises have different input states and the same output context. Runtime/static agreement H,ηtsΔ requires state equality and injective handle identities. The root steps are

dom(H)
H,η,open f;PtsH[open],η[f],P
TSO-Open
η(f)=H(){open,eof}
H,η,close f;PtsH,ηf,P
TSO-Close
η(f)=H()=open
H,η,read f as{PmPe}tsH,η,Pm
TSO-Read-More
η(f)=H()=open
H,η,read f as{PmPe}tsH[eof],η,Pe
TSO-Read-Eof

The call step unfolds a checked body after capture-avoiding renaming:

X:(x:File[q])ΔX=PXΩ
H,η,X(f)tsH,η,PX[f/x]
TSO-Call

For a fixed checked procedure table Ω, the call interface is X:(x:File[q])ΔX=PXΩf:File[q]X(f)ΔX[f/x]TSCall. Here dom(ΔX){x}. Its dynamic companion replaces X(f) by PX[f/x] after alpha-renaming every procedure-local handle binder fresh for the caller.

Chapter 53: three coeffect cards

A scalar structure (C,,c,use,ign,) has two monoids and two-sided distributivity of over c. A flat calculus adds c with rcsrcs and judgments Γ@fre:τ. Flat call-by-value beta contracts only arguments typed at use. Flat call-by-name preservation requires either top-pointedness or bottom-pointedness together with c==c, commutativity, and idempotence.

Its four typing rules are

@fignc:ι
F-Const
x:τ@fusex:τ
F-Var
Γ,x:σ@f(rcs)e:τ
Γ@frλx.e:σscτ
F-Abs
Γ1@fre1:σtcτΓ2@fse2:σ
Γ1,Γ2@f(rc(ts))e1e2:τ
F-App

The structural calculus annotates an n-variable context by a vector in Cn. Abstraction removes the last scalar into the latent arrow; application concatenates the function vector with the argument vector scaled by the latent scalar. Weakening appends ign, exchange swaps the corresponding vector cells, and contraction combines adjacent cells with c. Its substitution conclusion replaces the bound cell r by the vector rS. The binder and application rules expose how that vector changes:

Γ,x:σ@s(R++s)e:τ
Γ@sRλx.e:σscτ
S-Abs
Γ1@sRe1:σtcτΓ2@sSe2:σ
Γ1,Γ2@s(R++(tS))e1e2:τ
S-App

Search the book

Type to search the local edition.