Erasable coercions: a unified approach to type systems
Julien Cretin January 30, 2014
1 / 34
Erasable coercions: a unified approach to type systems Julien - - PowerPoint PPT Presentation
Erasable coercions: a unified approach to type systems Julien Cretin January 30, 2014 1 / 34 Background: machine language A machine executes programs written in machine language 2 / 34 Background: machine language A machine executes
1 / 34
2 / 34
2 / 34
3 / 34
3 / 34
3 / 34
4 / 34
4 / 34
5 / 34
6 / 34
6 / 34
7 / 34
7 / 34
7 / 34
ι
cc
8 / 34
◮ definition ◮ example 9 / 34
◮ definition ◮ example
ι )
◮ identify a set of atomic features ◮ present them as composable coercions ◮ define a unified framework of coercions 9 / 34
◮ definition ◮ example
ι )
◮ identify a set of atomic features ◮ present them as composable coercions ◮ define a unified framework of coercions
cc)
◮ general coercion abstraction ◮ first-class coercions 9 / 34
, a1 a2
λx a
π1 a π2 a
@ a1 a2
x
10 / 34
, a1 a2
λx a
π1 a π2 a
@ a1 a2
x
10 / 34
, a1 a2
λx a
π1 a π2 a
@ a1 a2
x
10 / 34
, a1 a2
λx a
π1 a π2 a
@ a1 a2
x
10 / 34
, a1 a2
λx a
π1 a π2 a
@ a1 a2
x
10 / 34
, a1 a2
λx a
π1 a π2 a
@ a1 a2
x
10 / 34
πi , a1 a2
11 / 34
πi , a1 a2
@ λx a b x x
a b b
11 / 34
πi , a1 a2
@ λx a b x x
a b b
πi λx a @ , a1 a2 b
11 / 34
πi @ λy @ π1 y π2 y , x1 x2
12 / 34
πi @ λy @ π1 y π2 y , x1 x2
12 / 34
πi @ λy @ π1 y π2 y , x1 x2 πi @ π1 y π2 y
12 / 34
πi @ λy @ π1 y π2 y , x1 x2 πi @ π1 , x1 x2 π2 , x1 x2
12 / 34
πi @ π1 , x1 x2 π2 , x1 x2
12 / 34
πi @ x1 x2 πi @ π1 , x1 x2 π2 , x1 x2
12 / 34
13 / 34
13 / 34
13 / 34
14 / 34
15 / 34
TermCoer
15 / 34
TermCoer
15 / 34
16 / 34
16 / 34
16 / 34
Γ τ1 × τ2
, a1
Γ τ1
a2
Γ τ2 Γ τi
πi a
Γ τ1 × τ2 Γ τ → ρ
λx a
Γ, (x : τ) ρ Γ ρ
@ a
Γ τ → ρ
b
Γ τ Γ Γ(x)
x
17 / 34
Γ τ1 × τ2
, a1
Γ τ1
a2
Γ τ2 Γ τi
πi a
Γ τ1 × τ2 Γ τ → ρ
λx a
Γ, (x : τ) ρ Γ ρ
@ a
Γ τ → ρ
b
Γ τ Γ Γ(x)
x
Γ ρ
G
a
Γ, Σ τ +Σ τ Γ ρ
G
a
Γ, Σ τ +Σ τ
TermCoer
G ⇒ Γ ⊢ (Σ ⊢ τ) ⊲ ρ
17 / 34
18 / 34
OldInst
[ρ]
Inst
[ρ] ⇒ Γ ⊢ ∀α τ ⊲ τ[α/ρ] 18 / 34
OldGen
Λα
Gen
Λα ⇒ Γ ⊢ ( α ⊢ τ ) ⊲ ∀α τ
OldInst
[ρ]
Inst
[ρ] ⇒ Γ ⊢ ∀α τ ⊲ τ[α/ρ] 18 / 34
OldGen
Λα
Gen
Λα ⇒ Γ ⊢ ( α ⊢ τ ) ⊲ ∀α τ
OldInst
[ρ]
Inst
[ρ] ⇒ Γ ⊢ ∀α τ ⊲ τ[α/ρ]
18 / 34
Γ τ
♦
+∅ τ
Refl
♦ ⇒ Γ ⊢ τ ⊲ τ
19 / 34
Γ τ
♦
+∅ τ
Refl
♦ ⇒ Γ ⊢ τ ⊲ τ
Γ τ3
G2 G1
+Σ1 τ1 Γ, Σ2 τ2 +Σ2 τ2
Γ τ3
G2 ◦ G1
+Σ2, Σ1 τ1
Trans
G2 ⇒ Γ ⊢ (Σ2 ⊢ τ2) ⊲ τ3 G1 ⇒ Γ, Σ2 ⊢ (Σ1 ⊢ τ1) ⊲ τ2 G2 ◦ G1 ⇒ Γ ⊢ (Σ2, Σ1 ⊢ τ1) ⊲ τ3
19 / 34
Γ τ
♦
+∅ τ
Refl
♦ ⇒ Γ ⊢ τ ⊲ τ
Γ τ3
G2 G1
+Σ1 τ1 Γ, Σ2 τ2 +Σ2 τ2
Γ τ3
G2 ◦ G1
+Σ2, Σ1 τ1
Trans
G2 ⇒ Γ ⊢ (Σ2 ⊢ τ2) ⊲ τ3 G1 ⇒ Γ, Σ2 ⊢ (Σ1 ⊢ τ1) ⊲ τ2 G2 ◦ G1 ⇒ Γ ⊢ (Σ2, Σ1 ⊢ τ1) ⊲ τ3
19 / 34
Γ τ
♦
+∅ τ
Refl
♦ ⇒ Γ ⊢ τ ⊲ τ
Γ τ3
G2 G1
+Σ1 τ1 Γ, Σ2 τ2 +Σ2 τ2
Γ τ3
G2 ◦ G1
+Σ2, Σ1 τ1
Trans
G2 ⇒ Γ ⊢ (Σ2 ⊢ τ2) ⊲ τ3 G1 ⇒ Γ, Σ2 ⊢ (Σ1 ⊢ τ1) ⊲ τ2 G2 ◦ G1 ⇒ Γ ⊢ (Σ2, Σ1 ⊢ τ1) ⊲ τ3
19 / 34
EtaProd
EtaArr
Note: You need one such rule for each of your computational types.
20 / 34
EtaProd
G1 ⇒ Γ ⊢ (Σ ⊢ τ1) ⊲ ρ1 G2 ⇒ Γ ⊢ (Σ ⊢ τ2) ⊲ ρ2 G1 × G2 ⇒ Γ ⊢ (Σ ⊢ τ1 × τ2) ⊲ ρ1 × ρ2
EtaArr
G1 ⇒ Γ, Σ ⊢ ρ1 ⊲ τ1 G2 ⇒ Γ ⊢ (Σ ⊢ τ2) ⊲ ρ2 G1 → G2 ⇒ Γ ⊢ (Σ ⊢ τ1 → τ2) ⊲ ρ1 → ρ2
Note: You need one such rule for each of your computational types.
20 / 34
η (Mitchell 1988)
21 / 34
η (Mitchell 1988)
(thanks to the use of coercions instead of just subtyping)
+ α
[α]
G
Λα
21 / 34
LowerInst
LowerGen
22 / 34
LowerInst
LowerGen
22 / 34
LowerInst
LowerGen
22 / 34
UpperInst
UpperGen
23 / 34
UpperInst
UpperGen
23 / 34
UpperInst
UpperGen
<: (Canning, Cook, Hill, Olthoff, Mitchell, 1989)
<: because coercions
23 / 34
24 / 34
24 / 34
25 / 34
25 / 34
25 / 34
25 / 34
ι (POPL 2012)
Erasable feature F F
η
MLF F
<:
Fp
ι
Polymorphism
√ √
Eta-expansion
√
Bottom
Top
√
Lower bounded polymorphism
Upper bounded polymorphism
√
<:, and F η (thus ML and F)
26 / 34
ι seems a local optimal
27 / 34
ι seems a local optimal
ι can only model bounded polymorphism with a single bound,
27 / 34
ι seems a local optimal
ι can only model bounded polymorphism with a single bound,
27 / 34
28 / 34
28 / 34
28 / 34
29 / 34
29 / 34
29 / 34
(if κ is {α : ⋆ | α ⊲ τ}, this implies the existence of a coercion of type ρ ⊲ τ)
ι
(witnesses are either top or bottom).
cc
(it is undecidable in the general case).
29 / 34
∂· a
Γ, (α : κ) τ Γ Π(α : κ) τ
·♦ a
Γ Π(α : κ) τ Γ τ[α/ρ]
·♦ ∂· a
Note: This construct breaks confluence, but confluence can easily be restored.
30 / 34
cc
ι and Constraint ML (thus MLF, F <:, F η, ML, and F)
31 / 34
32 / 34
33 / 34
34 / 34
cc would allow a syntactical approach?
34 / 34
34 / 34
Intro
Elim
i (Σi ⊢ τi) ⊲ ρ. Intro
Elim
Fusion
Intro
Elim
Weak
34 / 34
TermVar
TermLam
TermApp
TermCoer
34 / 34
Trans
i
Weak
EtaArr
Γ, Σi ⊢ τ ′ ⊲ τi i
34 / 34
Γ′
1 = Γ1, (x : τ1)
Γ′
2 = Γ2, (x : τ2)
M ⇒ a ⊢ Γ′
1 : ρ1
N ⇒ b ⊢ Γ2 : τ2 G ⇒ Γ2 ⊢ (Σ1 ⊢ τ1 → ρ1) ⊲ τ2 → ρ2
@ N G λ G λ M Γ2 Γ1 Γ′
1
ρ2 τ2 τ2 → ρ2 τ1 → ρ1 ρ1 τ1 @ LG N λ M λ @ RG LG Γ2 Γ1 Γ′
1
ρ2 ρ1 τ1 τ2 τ1 → ρ1 ρ1 τ1 @ N λ RG M LG λ M RG LG Γ2 Γ′
2 Γ′ 1
ρ2 τ2 τ2 → ρ2 ρ2 ρ1 τ1 τ2 RG M LG N M RG LG Γ2 Γ1 ρ2 ρ1 τ1 τ2
34 / 34
def
def
def
def
def
def
def
def
def
34 / 34
cc where type and coercion abstraction
34 / 34
Weak
G ⇒ Γ ⊢ (Σ ⊢ τ) ⊲ ρ ∗G ⇒ Γ ⊢ τ ⊲ ρ
Γ ρ
G
+∅ τ +Σ τ
34 / 34
Γ ⊤
⊤
+∅ τ
Top
⊤ ⇒ Γ ⊢ τ ⊲ ⊤
Γ τ
⊥τ
+∅ ⊥
Bot
⊥τ ⇒ Γ ⊢ ⊥ ⊲ τ 34 / 34
1 keep the calculus and use dependent types, 2 keep the calculus and use a standardization argument (Riba 2007), 3 change the calculus and use a simple argument, or 4 use the CPS encoding.
34 / 34
Γ τ1 × τ2
G1 × G2
+Σ τ ′
1 × τ ′ 2
Γ τ → ρ
G1 → G2
+Σ τ ′ → ρ′ Γ τ1 × τ2
,
G1
π1
τ ′
1 × τ ′ 2
+Σ τ ′
1
Γ τ1
G2
π2
τ ′
1 × τ ′ 2
+Σ τ ′
2
Γ τ2 Γ τ → ρ
λx
G2
@
τ ′ → ρ′
G1
x
τ τ ′ +Σ ρ′ Γ, (x : τ) ρ
34 / 34
+ α
[α]
[α] → Λα
Λα ⇒ Γ ⊢ ( α ⊢ ρ) ⊲ ∀α ρ [α] ⇒ Γ, α ⊢ ∀α τ ⊲ τ [α] → Λα ⇒ Γ ⊢ ( α ⊢ τ → ρ) ⊲ (∀α τ) → ∀α ρ 34 / 34
EquivPeriod
EtaMu
34 / 34
34 / 34
OK
OK
BAD
34 / 34
34 / 34
34 / 34
1
2
ι 3
cc 4
5
34 / 34