Lectures onType Theory
Linear and affine term calculus
appendix sectionrules

Linear and affine term calculus

The core signature of chapter 18 is A,B::=b1ABABAB!A,e::=xλx.ee1e2e1e2let xy=e1 in e2let =e1 in e2inleinrecase e of inlxe1inrye2!vlet !x=e1 in e2,v,w::=xλx.evwinlvinrv!v. The judgment is Γ;Δe:A. Both contexts are finite maps, their domains are disjoint, and exchange is map equality. Write Δ1#Δ2 for disjoint domains and Δ1Δ2 for their union under that premise. Every rule display containing carries the corresponding disjointness premise. The thirteen core typing rules are

x:AΓ
Γ;x:A
T-UVar
Γ;x:Ax:A
T-LVar
Γ;:1
T-OneI
Γ;Δ1e1:1Γ;Δ2e2:C
Γ;Δ1Δ2let =e1 in e2:C
T-OneE
Γ;Δ,x:Ae:B
Γ;Δλx.e:AB
T-LolliI
Γ;Δ1e1:ABΓ;Δ2e2:A
Γ;Δ1Δ2e1e2:B
T-LolliE
Γ;Δ1e1:AΓ;Δ2e2:B
Γ;Δ1Δ2e1e2:AB
T-TensorI
Γ;Δ1e1:ABΓ;Δ2,x:A,y:Be2:C
Γ;Δ1Δ2let xy=e1 in e2:C
T-TensorE
Γ;Δe:A
Γ;Δinle:AB
T-PlusI1
Γ;Δe:B
Γ;Δinre:AB
T-PlusI2
Γ;Δ0e0:ABΓ;Δr,x:Ae1:CΓ;Δr,y:Be2:C
Γ;Δ0Δrcase e0 of inlxe1inrye2:C
T-Case
Γ;v:A
Γ;!v:!A
T-BangI
Γ;Δ1e1:!AΓ,x:A;Δ2e2:B
Γ;Δ1Δ2let !x=e1 in e2:B
T-BangE

The premise of T-BangI is a value and has empty linear context.

Weak left-to-right call-by-value evaluation uses E::=[]EevEEevElet xy=E in elet =E in einlEinrEcase E of inlxe1inrye2let !x=E in e. There is no context beneath a lambda, bang, or unselected branch. The six core roots are

(λx.e)ve[v/x]
E-LinBeta
let xy=vw in ee[v/x,w/y]
E-Tensor
let = in ee
E-One
case (inlv) of inlxe1inrye2e1[v/x]
E-InL
case (inrv) of inlxe1inrye2e2[v/y]
E-InR
let !x=!v in ee[v/x]
E-Bang

The one-step relation is their compatible closure E[e]E[e].

For the token extension, fix an infinite set Tok and a finite live set HTok. Add atomic types File and Bytes, primitive values open, read, and close, and runtime values fileh,bytesh. The four closed typing axioms are

Γ;open:1File
T-Open
Γ;read:File(FileBytes)
T-Read
Γ;close:File1
T-Close
Γ;bytesh:Bytes
T-Bytes

There is no closed source typing axiom for fileh. Instead, He:A means that distinct placeholders (xh)hH and a template e0 satisfy ;(xh:File)hHe0:A,e=e0[fileh/xh]hH. Core steps leave H unchanged, and the additional roots are

hTokH
(H,open)(H{h},fileh)
E-Open
hH
(H,readfileh)(H,filehbytesh)
E-Read
hH
(H,closefileh)(H{h},)
E-Close

Finally, the affine, relevant, and unrestricted deltas retain all thirteen core rules with a uniform judgment subscript and add only

Γ;Δae:Axdom(Γ,Δ)
Γ;Δ,x:Bae:A
W-Aff
Γ;Δ,x:A,y:Are:Bzdom(Γ,Δ)
Γ;Δ,z:Are[z/x,z/y]:B
C-Rel

The unrestricted judgment has both rules with subscript u; the linear judgment has neither.

Rig-indexed dependent comparison

This source-bounded card is McBride’s dependent calculus [McB16], not an extension of the monomorphic linear calculus above. It borrows dependent-function and bidirectional vocabulary from chapter 26, chapter 27. To avoid collision with the chapter’s structural-regime notation, this card alpha-renames source R,Γ,Δ,ρ,π to Q,Θ,Ξ,q,p. A precontext Θ records variables and types. A Θ-context Ξ marks every variable of that same precontext by a quantity in the rig Q; addition and scalar multiplication of contexts are pointwise. The bidirectional judgments are ΞqTt,ΞqeS. Types are checked at quantity zero. The source application rule is

Ξ0qf(px:S)TΞ1qpSs
Ξ0+Ξ1qfsT[s:S/x]
R-App

Both premises mark one precontext, so a variable can remain available for forming the dependent result type even when its run-time quantity in one premise is zero.

The rigid system has no weakening rule. Section 12 of the source separately orders quantities, extends that order pointwise to contexts, and adds

ΞqTtΞΞ
ΞqTt
R-Weak

Retaining factorization, splitting, substitution, and safe erasure imposes the additional order conditions stated there. Thus zero-priced contemplation and ordered discardability are different rule cards; neither is a proof-irrelevance principle. Lemma 40’s unique-erasure conclusion has the additional hypothesis q0; the erasure development also assumes q+p=0q=0=p, the book’s rendering of the source’s “absence of negation” condition.

Search the book

Type to search the local edition.