Immutable-record subtyping and bounded quantification
appendix sectionrules
Immutable-record subtyping and bounded quantification
This section records the exact immutable-record and bounded-subtyping systems. The fixed records at the end of the preceding section were a static boundary for 𝐹𝜔 and had no reduction rules. The records below instead belong to an immutable call-by-value calculus. They are finite maps at both the type and term levels, and their fields evaluate in a fixed total order. Thus this section does not add dynamics to the preceding 𝐹𝜔 fragment.
The first-order declarative calculus
The complete first-order type grammar is 𝐴,𝐵::=𝖳𝗈𝗉∣𝖡𝗈𝗍∣𝖴𝗇𝗂𝗍∣𝖡𝗈𝗈𝗅∣𝖭𝖺𝗍∣𝐴→𝐵∣𝐴×𝐵∣𝐴+𝐵∣{ℓ𝑖:𝐴𝑖}𝑖∈𝐼. The index set 𝐼 is finite, displayed labels are distinct, and reordering a display does not change the finite map. The first-order context Γ contains term declarations only. All rules below are schemas over well-formed types. Formation of the complete grammar is
Γ𝖼𝗍𝗑
Γ⊢𝖳𝗈𝗉𝗍𝗒𝗉𝖾
B-Ty-Top
Γ𝖼𝗍𝗑
Γ⊢𝖡𝗈𝗍𝗍𝗒𝗉𝖾
B-Ty-Bot
Γ𝖼𝗍𝗑
Γ⊢𝖴𝗇𝗂𝗍𝗍𝗒𝗉𝖾
B-Ty-Unit
Γ𝖼𝗍𝗑
Γ⊢𝖡𝗈𝗈𝗅𝗍𝗒𝗉𝖾
B-Ty-Bool
Γ𝖼𝗍𝗑
Γ⊢𝖭𝖺𝗍𝗍𝗒𝗉𝖾
B-Ty-Nat
Γ⊢𝐴𝗍𝗒𝗉𝖾Γ⊢𝐵𝗍𝗒𝗉𝖾
Γ⊢𝐴→𝐵𝗍𝗒𝗉𝖾
B-Ty-Arr
Γ⊢𝐴𝗍𝗒𝗉𝖾Γ⊢𝐵𝗍𝗒𝗉𝖾
Γ⊢𝐴×𝐵𝗍𝗒𝗉𝖾
B-Ty-Prod
Γ⊢𝐴𝗍𝗒𝗉𝖾Γ⊢𝐵𝗍𝗒𝗉𝖾
Γ⊢𝐴+𝐵𝗍𝗒𝗉𝖾
B-Ty-Sum
Γ⊢𝐴𝑖𝗍𝗒𝗉𝖾forevery𝑖∈𝐼
Γ⊢{ℓ𝑖:𝐴𝑖}𝑖∈𝐼𝗍𝗒𝗉𝖾
B-Ty-Rcd
The declarative subtype judgment is Γ⊢𝐴<:𝐵.
Γ⊢𝐴𝗍𝗒𝗉𝖾
Γ⊢𝐴<:𝐴
S-Refl
Γ⊢𝐴<:𝐵Γ⊢𝐵<:𝐶
Γ⊢𝐴<:𝐶
S-Trans
Γ⊢𝐴𝗍𝗒𝗉𝖾
Γ⊢𝐴<:𝖳𝗈𝗉
S-Top
Γ⊢𝐴𝗍𝗒𝗉𝖾
Γ⊢𝖡𝗈𝗍<:𝐴
S-Bot
Γ⊢𝐵1<:𝐴1Γ⊢𝐴2<:𝐵2
Γ⊢𝐴1→𝐴2<:𝐵1→𝐵2
S-Arr
Γ⊢𝐴1<:𝐵1Γ⊢𝐴2<:𝐵2
Γ⊢𝐴1×𝐴2<:𝐵1×𝐵2
S-Prod
Γ⊢𝐴1<:𝐵1Γ⊢𝐴2<:𝐵2
Γ⊢𝐴1+𝐴2<:𝐵1+𝐵2
S-Sum
𝐽⊆𝐼Γ⊢𝐴𝑗<:𝐵𝑗forevery𝑗∈𝐽
Γ⊢{ℓ𝑖:𝐴𝑖}𝑖∈𝐼<:{ℓ𝑗:𝐵𝑗}𝑗∈𝐽
S-Rcd
The term grammar is the inherited explicitly typed call-by-value grammar with the delta 𝑡::=⋯∣0∣𝗌𝗎𝖼(𝑡)∣𝗇𝖺𝗍𝗋𝖾𝖼(𝑡;𝑡0;𝑥.𝑦.𝑡𝑠)::=∣{ℓ𝑖=𝑡𝑖}𝑖∈𝐼∣𝑡.ℓ,𝑣::=⋯∣0∣𝗌𝗎𝖼(𝑣)∣{ℓ𝑖=𝑣𝑖}𝑖∈𝐼. The natural-number typing delta is
Γ⊢0:𝖭𝖺𝗍
T-Zero
Γ⊢𝑡:𝖭𝖺𝗍
Γ⊢𝗌𝗎𝖼(𝑡):𝖭𝖺𝗍
T-Suc
Γ⊢𝑡:𝖭𝖺𝗍Γ⊢𝑡0:𝐴Γ,𝑥:𝖭𝖺𝗍,𝑦:𝐴⊢𝑡𝑠:𝐴
Γ⊢𝗇𝖺𝗍𝗋𝖾𝖼(𝑡;𝑡0;𝑥.𝑦.𝑡𝑠):𝐴
T-NatRec
Subsumption, record introduction, and projection are exactly
Γ⊢𝑡:𝐴Γ⊢𝐴<:𝐵
Γ⊢𝑡:𝐵
T-Sub
Γ⊢𝑡𝑖:𝐴𝑖forevery𝑖∈𝐼
Γ⊢{ℓ𝑖=𝑡𝑖}𝑖∈𝐼:{ℓ𝑖:𝐴𝑖}𝑖∈𝐼
T-Rcd
Γ⊢𝑡:{ℓ𝑖:𝐴𝑖}𝑖∈𝐼𝑘∈𝐼
Γ⊢𝑡.ℓ𝑘:𝐴𝑘
T-Proj
Natural-number evaluation adds the two congruences and two roots
Record evaluation adds the following three rules. In E-Rcd, ℓ𝑖<ℓ𝑘 refers to the fixed total order of labels.
𝑡𝑘⟶𝑡′𝑘𝑡𝑖isavalueforeveryℓ𝑖<ℓ𝑘
{…,ℓ𝑘=𝑡𝑘,…}⟶{…,ℓ𝑘=𝑡′𝑘,…}
E-Rcd
𝑘∈𝐼
{ℓ𝑖=𝑣𝑖}𝑖∈𝐼.ℓ𝑘⟶𝑣𝑘
E-Proj
𝑡⟶𝑡′
𝑡.ℓ𝑘⟶𝑡′.ℓ𝑘
E-ProjCong
There is no runtime form and no reduction rule for subsumption.
Kernel bounded quantification
Kernel 𝐹<: extends precisely the grammar above by 𝐴,𝐵::=⋯∣𝑋∣∀𝑋<:𝐴.𝐵,𝑡,𝑢::=⋯∣Λ𝑋<:𝐴.𝑡∣𝑡[𝐵]. Contexts now mix term declarations and type bounds. Every declaration is checked in the prefix to its left, so a newly declared 𝑋 cannot occur in its own bound. Lookup of a type bound is written Γ(𝑋)=𝐴.
⋅𝖼𝗍𝗑
C-Empty
Γ𝖼𝗍𝗑Γ⊢𝐴𝗍𝗒𝗉𝖾𝑥∉dom(Γ)
Γ,𝑥:𝐴𝖼𝗍𝗑
C-Term
Γ𝖼𝗍𝗑Γ⊢𝐴𝗍𝗒𝗉𝖾𝑋∉dom(Γ)
Γ,𝑋<:𝐴𝖼𝗍𝗑
C-Type
Type-variable and bounded-universal formation are
Γ(𝑋)=𝐴
Γ⊢𝑋𝗍𝗒𝗉𝖾
B-Ty-Var
Γ⊢𝐴𝗍𝗒𝗉𝖾Γ,𝑋<:𝐴⊢𝐵𝗍𝗒𝗉𝖾
Γ⊢∀𝑋<:𝐴.𝐵𝗍𝗒𝗉𝖾
B-Ty-All
The Kernel subtype and term rules added to the first-order tables are
Γ(𝑋)=𝐴
Γ⊢𝑋<:𝐴
S-Var
Γ,𝑋<:𝐴⊢𝐵<:𝐶
Γ⊢∀𝑋<:𝐴.𝐵<:∀𝑋<:𝐴.𝐶
S-AllK
Γ,𝑋<:𝐴⊢𝑡:𝐵
Γ⊢Λ𝑋<:𝐴.𝑡:∀𝑋<:𝐴.𝐵
T-TAbs
Γ⊢𝑡:∀𝑋<:𝐴.𝐵Γ⊢𝐶<:𝐴
Γ⊢𝑡[𝐶]:𝐵[𝐶/𝑋]
T-TApp
The two bounds in S-AllK are the same constructor modulo alpha-equivalence; the rule does not compare distinct bounds.
Type abstractions are values, type application evaluates its operator, and the one new root contraction is 𝑣::=⋯∣Λ𝑋<:𝐴.𝑡,𝐸::=⋯∣𝐸[𝐶],(Λ𝑋<:𝐴.𝑡)[𝐶]⟶𝑡[𝐶/𝑋].
The deterministic Kernel algorithm
The judgment Γ⊢a𝐴<:𝐵 is read by priority: test alpha-equality, then a top target, then a bottom source, then source-variable promotion, and only then matching outer constructors. A universal comparison fails when its two bounds are not alpha-identical. The following guards make that priority part of the derivation rather than an unstated implementation convention.
𝐴≡𝛼𝐵
Γ⊢a𝐴<:𝐵
A-Eq
𝐴≢𝛼𝖳𝗈𝗉
Γ⊢a𝐴<:𝖳𝗈𝗉
A-Top
𝐵≢𝛼𝖡𝗈𝗍𝐵≢𝛼𝖳𝗈𝗉
Γ⊢a𝖡𝗈𝗍<:𝐵
A-Bot
𝑋≢𝛼𝐵𝐵≢𝛼𝖳𝗈𝗉Γ(𝑋)=𝑈Γ⊢a𝑈<:𝐵
Γ⊢a𝑋<:𝐵
A-Var
𝐴1→𝐴2≢𝛼𝐵1→𝐵2Γ⊢a𝐵1<:𝐴1Γ⊢a𝐴2<:𝐵2
Γ⊢a𝐴1→𝐴2<:𝐵1→𝐵2
A-Arr
𝐴1×𝐴2≢𝛼𝐵1×𝐵2Γ⊢a𝐴1<:𝐵1Γ⊢a𝐴2<:𝐵2
Γ⊢a𝐴1×𝐴2<:𝐵1×𝐵2
A-Prod
𝐴1+𝐴2≢𝛼𝐵1+𝐵2Γ⊢a𝐴1<:𝐵1Γ⊢a𝐴2<:𝐵2
Γ⊢a𝐴1+𝐴2<:𝐵1+𝐵2
A-Sum
{ℓ𝑖:𝐴𝑖}𝑖∈𝐼≢𝛼{ℓ𝑗:𝐵𝑗}𝑗∈𝐽𝐽⊆𝐼Γ⊢a𝐴𝑗<:𝐵𝑗forevery𝑗∈𝐽
Γ⊢a{ℓ𝑖:𝐴𝑖}𝑖∈𝐼<:{ℓ𝑗:𝐵𝑗}𝑗∈𝐽
A-Rcd
∀𝑋<:𝐴.𝐵≢𝛼∀𝑋<:𝐴.𝐶Γ,𝑋<:𝐴⊢a𝐵<:𝐶
Γ⊢a∀𝑋<:𝐴.𝐵<:∀𝑋<:𝐴.𝐶
A-AllK
For records, target labels and their recursive premises are visited in the fixed label order. There is no target-promotion rule and no algorithmic transitivity rule.
Boundary table: full 𝐹<: is a replacement system
Full 𝐹<: omits bottom, products, sums, records, and the guarded Kernel algorithm. Its type grammar and contexts are 𝐴::=𝑋∣𝐴→𝐴∣∀𝑋<:𝐴.𝐴∣𝖳𝗈𝗉,Γ::=⋅∣Γ,𝑋<:𝐴. It retains only S-Refl, S-Trans, S-Top, S-Var, and S-Arr, restricted to this grammar, and replaces S-AllK by the rule below. Its body premise is checked under the target bound 𝑇1.
Γ⊢𝑇1<:𝑆1Γ,𝑋<:𝑇1⊢𝑆2<:𝑇2
Γ⊢∀𝑋<:𝑆1.𝑆2<:∀𝑋<:𝑇1.𝑇2
S-AllF
A closed decision input may have a nonempty bound context. Precisely, Γ=𝑋1<:𝐴1,…,𝑋𝑛<:𝐴𝑛 is closed when each 𝐴𝑖 mentions only earlier 𝑋𝑗, and Γ⊢𝑆<:𝑇 is closed when every free variable of 𝑆,𝑇 is declared in Γ. This is the input class of theorem 8.29; it is not restricted to Γ=⋅.