The source and target of chapter 11 share 𝐴,𝐵::=𝟐∣ℕ∣?∣𝐴→𝐵,𝐺::=𝟐∣ℕ∣?→?. For every 𝐴≠?, the ground-shape operation used below is 𝗀𝗇𝖽(𝟐)=𝟐,𝗀𝗇𝖽(ℕ)=ℕ,𝗀𝗇𝖽(𝐴→𝐵)=?→?. Consistency is the least relation generated by
?∼𝖼𝐴
C-UnkL
𝐴∼𝖼?
C-UnkR
𝟐∼𝖼𝟐
C-Bool
ℕ∼𝖼ℕ
C-Nat
𝐴1∼𝖼𝐵1𝐴2∼𝖼𝐵2
𝐴1→𝐴2∼𝖼𝐵1→𝐵2
C-Arr
Function matching is the partial operation 𝖿𝗎𝗇(𝐴→𝐵)=𝐴→𝐵 and 𝖿𝗎𝗇(?)=?→?. For 𝑒::=𝑏∣𝑛∣𝑥∣𝜆𝑥:𝐴.𝑒∣(𝑒1𝑒2)ℓ, the complete source table is
Γ⊢𝑏:𝟐
G-Bool
Γ⊢𝑛:ℕ
G-Nat
𝑥:𝐴∈Γ
Γ⊢𝑥:𝐴
G-Var
Γ,𝑥:𝐴⊢𝑒:𝐵
Γ⊢𝜆𝑥:𝐴.𝑒:𝐴→𝐵
G-Lam
Γ⊢𝑒1:𝐶𝖿𝗎𝗇(𝐶)=𝐴→𝐵Γ⊢𝑒2:𝐷𝐷∼𝖼𝐴
Γ⊢(𝑒1𝑒2)ℓ:𝐵
G-App
Target terms and blame-label complementation are 𝑎::=𝑏∣𝑛∣𝑥∣𝜆𝑥:𝐴.𝑎∣𝑎1𝑎2∣⟨𝐵⇐𝐴⟩𝑝𝑎∣𝖻𝗅𝖺𝗆𝖾𝑝,――¯𝑝=𝑝. Their complete typing table is
Γ⊢𝐶𝑏:𝟐
T-Bool
Γ⊢𝐶𝑛:ℕ
T-Nat
𝑥:𝐴∈Γ
Γ⊢𝐶𝑥:𝐴
T-Var
Γ,𝑥:𝐴⊢𝐶𝑎:𝐵
Γ⊢𝐶𝜆𝑥:𝐴.𝑎:𝐴→𝐵
T-Lam
Γ⊢𝐶𝑎1:𝐴→𝐵Γ⊢𝐶𝑎2:𝐴
Γ⊢𝐶𝑎1𝑎2:𝐵
T-App
Γ⊢𝐶𝑎:𝐴𝐴∼𝖼𝐵
Γ⊢𝐶⟨𝐵⇐𝐴⟩𝑝𝑎:𝐵
T-Cast
Γ⊢𝐶𝖻𝗅𝖺𝗆𝖾𝑝:𝐵
T-Blame
The value and evaluation-frame grammars are 𝑣::=𝑏∣𝑛∣𝜆𝑥:𝐴.𝑎∣⟨𝐴2→𝐵2⇐𝐴1→𝐵1⟩𝑝𝑣∣⟨?⇐𝐺⟩𝑝𝑣,𝐹::=[]𝑎∣𝑣[]∣⟨𝐵⇐𝐴⟩𝑝[]. Reduction is compatible with 𝐸::=[]∣𝐹[𝐸] and has exactly
(𝜆𝑥:𝐴.𝑎)𝑣⟼𝑎[𝑣/𝑥]
E-Beta
𝐵∈{𝟐,ℕ}
⟨𝐵⇐𝐵⟩𝑝𝑣⟼𝑣
E-IdBase
⟨?⇐?⟩𝑝𝑣⟼𝑣
E-IdUnk
⟨𝐺⇐?⟩𝑝(⟨?⇐𝐺⟩𝑞𝑣)⟼𝑣
E-Project
𝐺1≠𝐺2
⟨𝐺2⇐?⟩𝑝(⟨?⇐𝐺1⟩𝑞𝑣)⟼𝖻𝗅𝖺𝗆𝖾𝑝
E-Mismatch
𝐴≠?𝐴≠𝗀𝗇𝖽(𝐴)
⟨?⇐𝐴⟩𝑝𝑣⟼⟨?⇐𝗀𝗇𝖽(𝐴)⟩𝑝(⟨𝗀𝗇𝖽(𝐴)⇐𝐴⟩𝑝𝑣)
E-Ground
𝐴≠?𝐴≠𝗀𝗇𝖽(𝐴)
⟨𝐴⇐?⟩𝑝𝑣⟼⟨𝐴⇐𝗀𝗇𝖽(𝐴)⟩𝑝(⟨𝗀𝗇𝖽(𝐴)⇐?⟩𝑝𝑣)
E-Expand
𝑢=⟨𝐴2→𝐵2⇐𝐴1→𝐵1⟩𝑝𝑣
𝑢𝑤⟼⟨𝐵2⇐𝐵1⟩𝑝(𝑣(⟨𝐴1⇐𝐴2⟩¯𝑝𝑤))
E-WrapApp
𝐹[𝖻𝗅𝖺𝗆𝖾𝑝]⟼𝖻𝗅𝖺𝗆𝖾𝑝
E-Blame
The polar blame-safety orders are generated by
𝟐⪯+𝟐
P-Bool
ℕ⪯+ℕ
P-Nat
𝐴⪯+?
P-Unk
𝐵1⪯−𝐴1𝐴2⪯+𝐵2
𝐴1→𝐴2⪯+𝐵1→𝐵2
P-Arr
𝟐⪯−𝟐
N-Bool
ℕ⪯−ℕ
N-Nat
?⪯−𝐴
N-Unk
𝐴⪯−𝐺
𝐴⪯−?
N-GroundUnk
𝐵1⪯+𝐴1𝐴2⪯−𝐵2
𝐴1→𝐴2⪯−𝐵1→𝐵2
N-Arr
Here 𝐺 is ground in N-GroundUnk.
Cast insertion has the complete table
Γ⊢𝑏⇝𝑏:𝟐
I-Bool
Γ⊢𝑛⇝𝑛:ℕ
I-Nat
𝑥:𝐴∈Γ
Γ⊢𝑥⇝𝑥:𝐴
I-Var
Γ,𝑥:𝐴⊢𝑒⇝𝑎:𝐵
Γ⊢𝜆𝑥:𝐴.𝑒⇝𝜆𝑥:𝐴.𝑎:𝐴→𝐵
I-Lam
Γ⊢𝑒1⇝𝑎1:𝐶𝖿𝗎𝗇(𝐶)=𝐴→𝐵Γ⊢𝑒2⇝𝑎2:𝐷𝐷∼𝖼𝐴
Γ⊢(𝑒1𝑒2)ℓ⇝(⟨𝐴→𝐵⇐𝐶⟩ℓ𝑓𝑎1)(⟨𝐴⇐𝐷⟩ℓ𝑎𝑎2):𝐵
I-App
Here ℓ𝑓,ℓ𝑎 are globally fresh roots determined by ℓ.
Type and context precision are
𝐴⊑𝗍𝗒?
Pr-Unk
𝟐⊑𝗍𝗒𝟐
Pr-Bool
ℕ⊑𝗍𝗒ℕ
Pr-Nat
𝐴1⊑𝗍𝗒𝐵1𝐴2⊑𝗍𝗒𝐵2
𝐴1→𝐴2⊑𝗍𝗒𝐵1→𝐵2
Pr-Arr
⋅⊑𝖼𝗍𝗑⋅
PrCtx-Empty
Γ⊑𝖼𝗍𝗑Γ′𝐴⊑𝗍𝗒𝐴′
Γ,𝑥:𝐴⊑𝖼𝗍𝗑Γ′,𝑥:𝐴′
PrCtx-Extend
Source-term precision is the least compatible relation generated by
𝑏⊑𝗌𝗋𝖼𝑏
PrTm-Bool
𝑛⊑𝗌𝗋𝖼𝑛
PrTm-Nat
𝑥⊑𝗌𝗋𝖼𝑥
PrTm-Var
𝐴⊑𝗍𝗒𝐴′𝑒⊑𝗌𝗋𝖼𝑒′
𝜆𝑥:𝐴.𝑒⊑𝗌𝗋𝖼𝜆𝑥:𝐴′.𝑒′
PrTm-Lam
𝑒1⊑𝗌𝗋𝖼𝑒′1𝑒2⊑𝗌𝗋𝖼𝑒′2
(𝑒1𝑒2)ℓ⊑𝗌𝗋𝖼(𝑒′1𝑒′2)ℓ
PrTm-App
For Δ=(𝑥1:𝐴1⊑𝗍𝗒𝐴′1,…,𝑥𝑛:𝐴𝑛⊑𝗍𝗒𝐴′𝑛), target precision presupposes both projected target typings and the displayed result-type precision, where Δ𝐿=(𝑥1:𝐴1,…,𝑥𝑛:𝐴𝑛),Δ𝑅=(𝑥1:𝐴′1,…,𝑥𝑛:𝐴′𝑛). Its structural rules are
Δ⊢𝑏:𝟐⊑𝖢𝑏:𝟐
CPr-Bool
Δ⊢𝑛:ℕ⊑𝖢𝑛:ℕ
CPr-Nat
𝑥:𝐴⊑𝗍𝗒𝐴′∈Δ
Δ⊢𝑥:𝐴⊑𝖢𝑥:𝐴′
CPr-Var
𝐴⊑𝗍𝗒𝐴′Δ,𝑥:𝐴⊑𝗍𝗒𝐴′⊢𝑎:𝐵⊑𝖢𝑎′:𝐵′
Δ⊢𝜆𝑥:𝐴.𝑎:𝐴→𝐵⊑𝖢𝜆𝑥:𝐴′.𝑎′:𝐴′→𝐵′
CPr-Lam
Δ⊢𝑎1:𝐴→𝐵⊑𝖢𝑎′1:𝐴′→𝐵′Δ⊢𝑎2:𝐴⊑𝖢𝑎′2:𝐴′
Δ⊢𝑎1𝑎2:𝐵⊑𝖢𝑎′1𝑎′2:𝐵′
CPr-App
The remaining rules are
Δ⊢𝑎:𝑆⊑𝖢𝑎′:𝑆′𝑆∼𝖼𝑇𝑆′∼𝖼𝑇′𝑇⊑𝗍𝗒𝑇′
Δ⊢⟨𝑇⇐𝑆⟩𝑝𝑎:𝑇⊑𝖢⟨𝑇′⇐𝑆′⟩𝑝𝑎′:𝑇′
CPr-Cast
Δ⊢𝑎:𝑆⊑𝖢𝑎′:𝑈𝑆∼𝖼𝑇𝑇⊑𝗍𝗒𝑈
Δ⊢⟨𝑇⇐𝑆⟩𝑝𝑎:𝑇⊑𝖢𝑎′:𝑈
CPr-CastL
Δ⊢𝑎:𝑆⊑𝖢𝑎′:𝑈𝑈∼𝖼𝑉𝑆⊑𝗍𝗒𝑉
Δ⊢𝑎:𝑆⊑𝖢⟨𝑉⇐𝑈⟩𝑝𝑎′:𝑉
CPr-CastR
Δ𝑅⊢𝐶𝑎′:𝐴′𝐴⊑𝗍𝗒𝐴′
Δ⊢𝖻𝗅𝖺𝗆𝖾𝑝:𝐴⊑𝖢𝑎′:𝐴′
CPr-Blame
There is no rule relating an arbitrary left term to right-hand blame.
For Δ=(𝑥1:𝐴1⊑𝗍𝗒𝐴′1,…,𝑥𝑛:𝐴𝑛⊑𝗍𝗒𝐴′𝑛), related closing substitutions are 𝜌=(𝑣1/𝑥1,…,𝑣𝑛/𝑥𝑛)⊑𝖾𝑛𝑣𝜌′=(𝑣′1/𝑥1,…,𝑣′𝑛/𝑥𝑛) exactly when every 𝑣𝑖,𝑣′𝑖 is closed and ⋅⊢𝑣𝑖:𝐴𝑖⊑𝖢𝑣′𝑖:𝐴′𝑖. Simultaneous substitution is written 𝑎[𝜌].
Related evaluation frames have the rules
Δ⊢𝑎:𝐴⊑𝖢𝑎′:𝐴′𝐵⊑𝗍𝗒𝐵′
Δ⊢[]𝑎:(𝐴→𝐵)⇒𝐵⊑𝖥[]𝑎′:(𝐴′→𝐵′)⇒𝐵′
FPr-AppL
Δ⊢𝑣:𝐴→𝐵⊑𝖢𝑣′:𝐴′→𝐵′
Δ⊢𝑣[]:𝐴⇒𝐵⊑𝖥𝑣′[]:𝐴′⇒𝐵′
FPr-AppR
𝑆⊑𝗍𝗒𝑆′𝑆∼𝖼𝑇𝑆′∼𝖼𝑇′𝑇⊑𝗍𝗒𝑇′
Δ⊢⟨𝑇⇐𝑆⟩𝑝[]:𝑆⇒𝑇⊑𝖥⟨𝑇′⇐𝑆′⟩𝑝[]:𝑆′⇒𝑇′
FPr-Cast
Evaluation-context precision is the reflexive transitive closure generated by
𝑆⊑𝗍𝗒𝑆′
Δ⊢[]:𝑆⇒𝑆⊑𝖥[]:𝑆′⇒𝑆′
FPr-Hole
Δ⊢𝐸:𝑆⇒𝑇⊑𝖥𝐸′:𝑆′⇒𝑇′Δ⊢𝐹:𝑇⇒𝑈⊑𝖥𝐹′:𝑇′⇒𝑈′
Δ⊢𝐹[𝐸]:𝑆⇒𝑈⊑𝖥𝐹′[𝐸′]:𝑆′⇒𝑈′
FPr-Cons
For a cast descriptor, the charge is 𝜒(𝑇,𝑆):=⎧{
{⎨{
{⎩3𝑇=?and𝑆isneitherunknownnorground,3𝑆=?and𝑇isneitherunknownnorground,1otherwise. The total cast weight cw(𝑎) is structural: constants, variables, and blame contribute zero; abstraction takes its body’s weight; application adds both subterm weights; and cw(⟨𝑇⇐𝑆⟩𝑝𝑎)=𝜒(𝑇,𝑆)+cw(𝑎). With |𝑎| the syntax-tree size, the stutter measure is st(𝑎)=(cw(𝑎),|𝑎|)∈ℕ×ℕ in lexicographic order. Total weight includes descriptors in waiting arguments and beneath values, so a change of the next-redex position cannot increase the measure after an administrative cast contraction.
Separate dependent-interoperability card.
The SD comparison has a simply typed component 𝑠:𝑆, a dependently typed component 𝑡:𝑇, compatibility 𝑆⟺𝑇, and boundaries 𝖲𝖣𝑇𝑆(𝑡):𝑆,𝖣𝖲𝑆𝑇(𝑠):𝑇. For paired constructor declarations 𝐶:𝑆1→𝐴 and 𝐶:(𝑦:𝑇1)→𝐵𝑡1, the constructor-specific roots are 𝖲𝖣𝐵𝑡𝐴(𝐶𝑣)⟶𝖲𝖣𝐶𝑢if𝖺𝗋𝗀𝖳𝗈𝖲𝐶(𝑣)=𝑢, and 𝖣𝖲𝐴𝐵𝑡(𝐶𝑢)⟶𝖲𝖣(𝑡̃=[𝑣/𝑦]𝑡1)▹𝐶𝑣if𝖺𝗋𝗀𝖳𝗈𝖣𝐶(𝑢)=𝑣. The guard returns its payload when the two closed first-order indices are equal and 𝖾𝗋𝗋𝗈𝗋 otherwise. Call-by-value contexts descend into boundary operands. This card is the signature of definition 23.53; it adds no rule to the gradual cast calculus above.