Higher-kinded polymorphism and existential packages
appendix sectionrules
Higher-kinded polymorphism and existential packages
Kinds and constructors are 𝜅::=𝖳𝗒∣𝜅→𝜅,𝐴::=𝑢∣ℕ∣𝐴→𝐴∣𝐴×𝐴∣∀𝑢::𝜅.𝐴∣∃𝑢::𝜅.𝐴∣𝜆𝑢::𝜅.𝐴∣𝐴𝐴. Kind contexts contain distinct variables. The complete kinding rules are preceded by formation:
⋅𝗄𝖼𝗍𝗑
KCtx-Empty
Δ𝗄𝖼𝗍𝗑𝑢∉dom(Δ)
Δ,𝑢::𝜅𝗄𝖼𝗍𝗑
KCtx-Ext
The kinding rules are
(𝑢::𝜅)∈Δ
Δ⊢𝑢::𝜅
K-Var
Δ⊢ℕ::𝖳𝗒
K-Nat
Δ⊢𝐴::𝖳𝗒Δ⊢𝐵::𝖳𝗒
Δ⊢𝐴→𝐵::𝖳𝗒
K-Arr
Δ⊢𝐴::𝖳𝗒Δ⊢𝐵::𝖳𝗒
Δ⊢𝐴×𝐵::𝖳𝗒
K-Prod
Δ,𝑢::𝜅⊢𝐴::𝖳𝗒
Δ⊢∀𝑢::𝜅.𝐴::𝖳𝗒
K-All
Δ,𝑢::𝜅⊢𝐴::𝖳𝗒
Δ⊢∃𝑢::𝜅.𝐴::𝖳𝗒
K-Some
Δ,𝑢::𝜅1⊢𝐴::𝜅2
Δ⊢𝜆𝑢::𝜅1.𝐴::𝜅1→𝜅2
K-Abs
Δ⊢𝐴::𝜅1→𝜅2Δ⊢𝐵::𝜅1
Δ⊢𝐴𝐵::𝜅2
K-App
Constructor one-step reduction is generated by constructor beta and the complete congruence family below:
(𝜆𝑢::𝜅.𝐴)𝐵⟶𝛽𝐴[𝐵/𝑢]
TR-Beta
𝐴⟶𝛽𝐴′
𝐴𝐵⟶𝛽𝐴′𝐵
TR-App_1
𝐵⟶𝛽𝐵′
𝐴𝐵⟶𝛽𝐴𝐵′
TR-App_2
𝐴⟶𝛽𝐴′
(𝐴→𝐵)⟶𝛽(𝐴′→𝐵)
TR-Arr_1
𝐵⟶𝛽𝐵′
(𝐴→𝐵)⟶𝛽(𝐴→𝐵′)
TR-Arr_2
𝐴⟶𝛽𝐴′
𝐴×𝐵⟶𝛽𝐴′×𝐵
TR-Prod_1
𝐵⟶𝛽𝐵′
𝐴×𝐵⟶𝛽𝐴×𝐵′
TR-Prod_2
𝐴⟶𝛽𝐴′
𝜆𝑢::𝜅.𝐴⟶𝛽𝜆𝑢::𝜅.𝐴′
TR-Abs
𝐴⟶𝛽𝐴′
∀𝑢::𝜅.𝐴⟶𝛽∀𝑢::𝜅.𝐴′
TR-All
𝐴⟶𝛽𝐴′
∃𝑢::𝜅.𝐴⟶𝛽∃𝑢::𝜅.𝐴′
TR-Some
Constructor equality is the equivalence and congruence generated by constructor beta. Its complete noncongruence rules are
Δ⊢𝐴::𝜅
Δ⊢𝐴≡𝐴::𝜅
Q-Refl
Δ⊢𝐴≡𝐵::𝜅
Δ⊢𝐵≡𝐴::𝜅
Q-Sym
Δ⊢𝐴≡𝐵::𝜅Δ⊢𝐵≡𝐶::𝜅
Δ⊢𝐴≡𝐶::𝜅
Q-Trans
Δ,𝑢::𝜅1⊢𝐴::𝜅2Δ⊢𝐵::𝜅1
Δ⊢(𝜆𝑢::𝜅1.𝐴)𝐵≡𝐴[𝐵/𝑢]::𝜅2
Q-Beta
The complete congruence family is
Δ⊢𝐴1≡𝐵1::𝖳𝗒Δ⊢𝐴2≡𝐵2::𝖳𝗒
Δ⊢𝐴1→𝐴2≡𝐵1→𝐵2::𝖳𝗒
Q-Arr
Δ⊢𝐴1≡𝐵1::𝖳𝗒Δ⊢𝐴2≡𝐵2::𝖳𝗒
Δ⊢𝐴1×𝐴2≡𝐵1×𝐵2::𝖳𝗒
Q-Prod
Δ,𝑢::𝜅⊢𝐴≡𝐵::𝖳𝗒
Δ⊢∀𝑢::𝜅.𝐴≡∀𝑢::𝜅.𝐵::𝖳𝗒
Q-All
Δ,𝑢::𝜅⊢𝐴≡𝐵::𝖳𝗒
Δ⊢∃𝑢::𝜅.𝐴≡∃𝑢::𝜅.𝐵::𝖳𝗒
Q-Some
Δ,𝑢::𝜅1⊢𝐴≡𝐵::𝜅2
Δ⊢𝜆𝑢::𝜅1.𝐴≡𝜆𝑢::𝜅1.𝐵::𝜅1→𝜅2
Q-Abs
Δ⊢𝐴1≡𝐵1::𝜅1→𝜅2Δ⊢𝐴2≡𝐵2::𝜅1
Δ⊢𝐴1𝐴2≡𝐵1𝐵2::𝜅2
Q-App
The first line of the term grammar is the pure 𝐹𝜔 language of chapter 9; the second line is the package extension of chapter 10: 𝑒::=𝑥∣𝜆𝑥:𝐴.𝑒∣𝑒𝑒∣Λ𝑢::𝜅.𝑒∣𝑒[𝐴]∣⟨𝑒,𝑒⟩∣𝗉𝗋𝗃𝑖𝑒∣𝟢∣𝗌𝗎𝖼(𝑒)∣𝗉𝖺𝖼𝗄[𝐶,𝑒]𝖺𝗌∃𝑢::𝜅.𝐴∣𝗎𝗇𝗉𝖺𝖼𝗄[𝑢,𝑥]=𝑒𝗂𝗇𝑒. Its complete typing table is formed over term contexts generated by
Δ𝗄𝖼𝗍𝗑
Δ⊢⋅𝖼𝗍𝗑
Ctx-Empty
Δ⊢Γ𝖼𝗍𝗑Δ⊢𝐴::𝖳𝗒𝑥∉dom(Γ)
Δ⊢Γ,𝑥:𝐴𝖼𝗍𝗑
Ctx-Ext
The typing rules are
(𝑥:𝐴)∈Γ
Δ;Γ⊢𝑥:𝐴
T-Var
Δ⊢𝐴::𝖳𝗒Δ;Γ,𝑥:𝐴⊢𝑒:𝐵
Δ;Γ⊢𝜆𝑥:𝐴.𝑒:𝐴→𝐵
T-Lam
Δ;Γ⊢𝑒1:𝐴→𝐵Δ;Γ⊢𝑒2:𝐴
Δ;Γ⊢𝑒1𝑒2:𝐵
T-App
Δ,𝑢::𝜅;Γ⊢𝑒:𝐴
Δ;Γ⊢Λ𝑢::𝜅.𝑒:∀𝑢::𝜅.𝐴
T-TLam
Δ;Γ⊢𝑒:∀𝑢::𝜅.𝐴Δ⊢𝐶::𝜅
Δ;Γ⊢𝑒[𝐶]:𝐴[𝐶/𝑢]
T-TApp
Δ;Γ⊢𝑒1:𝐴1Δ;Γ⊢𝑒2:𝐴2
Δ;Γ⊢(𝑒1,𝑒2):𝐴1×𝐴2
T-Pair
Δ;Γ⊢𝑒:𝐴1×𝐴2
Δ;Γ⊢𝗉𝗋𝑖𝑒:𝐴𝑖
T-Prj
Δ;Γ⊢𝟢:ℕ
T-Zero
Δ;Γ⊢𝑒:ℕ
Δ;Γ⊢𝗌𝗎𝖼(𝑒):ℕ
T-Suc
Δ;Γ⊢𝑒:𝐴Δ⊢𝐴≡𝐵::𝖳𝗒
Δ;Γ⊢𝑒:𝐵
T-Conv
The existential rules, including the nonescape premise, are
Δ⊢𝐶::𝜅Δ,𝑢::𝜅⊢𝐴::𝖳𝗒Δ;Γ⊢𝑒:𝐴[𝐶/𝑢]
Δ;Γ⊢𝗉𝖺𝖼𝗄[𝐶,𝑒]𝖺𝗌∃𝑢::𝜅.𝐴:∃𝑢::𝜅.𝐴
T-Pack
Δ;Γ⊢𝑒1:∃𝑢::𝜅.𝐴Δ,𝑢::𝜅;Γ,𝑥:𝐴⊢𝑒2:𝐵Δ⊢𝐵::𝖳𝗒
Δ;Γ⊢𝗎𝗇𝗉𝖺𝖼𝗄[𝑢,𝑥]=𝑒1𝗂𝗇𝑒2:𝐵
T-Unpack
The last formation premise is the escape check: 𝑢 cannot occur free in 𝐵 because 𝐵 is formed before 𝑢 is added.
Call-by-value evaluation uses 𝑣::=𝜆𝑥:𝐴.𝑒∣Λ𝑢::𝜅.𝑒∣(𝑣1,𝑣2)∣𝟢∣𝗌𝗎𝖼(𝑣)∣𝗉𝖺𝖼𝗄[𝐶,𝑣]𝖺𝗌∃𝑢::𝜅.𝐴,𝐸::=[]∣𝐸𝑒∣𝑣𝐸∣𝐸[𝐶]∣(𝐸,𝑒)∣(𝑣,𝐸)∣𝗉𝗋𝑖𝐸∣𝗌𝗎𝖼(𝐸)∣𝗉𝖺𝖼𝗄[𝐶,𝐸]𝖺𝗌∃𝑢::𝜅.𝐴∣𝗎𝗇𝗉𝖺𝖼𝗄[𝑢,𝑥]=𝐸𝗂𝗇𝑒. Deleting the final value and the final two context productions gives a context grammar equivalent to the complete pure congruence family of definition 11.7. The package chapter adds those productions without changing the order of the pure ones. The pure calculus has the three root contractions
(𝜆𝑥:𝐴.𝑒)𝑣⟶𝑒[𝑣/𝑥]
E-Beta
(Λ𝑢::𝜅.𝑒)[𝐶]⟶𝑒[𝐶/𝑢]
E-TBeta
𝑖∈{1,2}
𝗉𝗋𝑖(𝑣1,𝑣2)⟶𝑣𝑖
E-PrjPair
Its complete congruence family is
𝑒1⟶𝑒′1
𝑒1𝑒2⟶𝑒′1𝑒2
E-App_1
𝑒2⟶𝑒′2
𝑣1𝑒2⟶𝑣1𝑒′2
E-App_2
𝑒⟶𝑒′
𝑒[𝐶]⟶𝑒′[𝐶]
E-TApp
𝑒1⟶𝑒′1
(𝑒1,𝑒2)⟶(𝑒′1,𝑒2)
E-Pair_1
𝑒2⟶𝑒′2
(𝑣1,𝑒2)⟶(𝑣1,𝑒′2)
E-Pair_2
𝑒⟶𝑒′
𝗉𝗋𝑖𝑒⟶𝗉𝗋𝑖𝑒′
E-Prj
𝑒⟶𝑒′
𝗌𝗎𝖼(𝑒)⟶𝗌𝗎𝖼(𝑒′)
E-Suc
The package-opening extension is 𝗎𝗇𝗉𝖺𝖼𝗄[𝑢,𝑥]=(𝗉𝖺𝖼𝗄[𝐶,𝑣]𝖺𝗌∃𝑎::𝜅.𝐴0)𝗂𝗇𝑒⟶𝑒[𝐶/𝑢][𝑣/𝑥]. The contextual rule is 𝑒⟶𝑒′⇒𝐸⟨𝑒⟩⟶𝐸⟨𝑒′⟩; there are no other call-by-value steps.
Compatible term beta is closed under every term constructor and has four roots: (𝜆𝑥:𝐴.𝑒)𝑑⟶𝛽𝑒[𝑑/𝑥],(Λ𝑢::𝜅.𝑒)[𝐶]⟶𝛽𝑒[𝐶/𝑢],𝗉𝗋𝑖(𝑒1,𝑒2)⟶𝛽𝑒𝑖,𝗎𝗇𝗉𝖺𝖼𝗄[𝑢,𝑥]=(𝗉𝖺𝖼𝗄[𝐶,𝑑]𝖺𝗌∃𝑎::𝜅.𝐴0)𝗂𝗇𝑒⟶𝛽𝑒[𝐶/𝑢][𝑑/𝑥].
For the static fixed-record boundary used at the end of the chapter, extend the grammars by 𝐴::=⋯∣{ℓ𝑖:𝐴𝑖}𝑖∈𝐼,𝑒::=⋯∣{ℓ𝑖=𝑒𝑖}𝑖∈𝐼∣𝑒.ℓ, where the finite label set contains no duplicates. The complete additional static rules are
Δ⊢𝐴𝑖::𝖳𝗒(𝑖∈𝐼)
Δ⊢{ℓ𝑖:𝐴𝑖}𝑖∈𝐼::𝖳𝗒
Rec-F
Δ;Γ⊢𝑒𝑖:𝐴𝑖(𝑖∈𝐼)
Δ;Γ⊢{ℓ𝑖=𝑒𝑖}𝑖∈𝐼:{ℓ𝑖:𝐴𝑖}𝑖∈𝐼
Rec-I
Δ;Γ⊢𝑒:{ℓ𝑖:𝐴𝑖}𝑖∈𝐼𝑗∈𝐼
Δ;Γ⊢𝑒.ℓ𝑗:𝐴𝑗
Rec-E
Δ⊢𝐴𝑖≡𝐵𝑖::𝖳𝗒(𝑖∈𝐼)
Δ⊢{ℓ𝑖:𝐴𝑖}𝑖∈𝐼≡{ℓ𝑖:𝐵𝑖}𝑖∈𝐼::𝖳𝗒
Q-Rec
This record delta is static only; the chapter states no record dynamics.