type assignment for intersections and unions in call-by-value … · in call-by-value languages...
TRANSCRIPT
![Page 1: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/1.jpg)
Type assignmentfor intersections and unionsin call-by-value languages
Joshua Dunfield and Frank Pfenning
Triple Project
Carnegie Mellon University
8 April 2003
FOSSACS ’03, Warsaw, Poland
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.1/42
![Page 2: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/2.jpg)
Outline
Motivation
Language
Datasort refinements
Index refinements
Intersections
Indefinite types
Related work
Conclusion & future work
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.2/42
![Page 3: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/3.jpg)
Motivation
Conventional type systems: ML, Java, . . .Tractable and easy to useLimited expressive power
Refined type systems:Tractable and easy to useBetter expressive power
Fully dependent type systems: Nuprl, . . .UndecidableExtremely expressive
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.3/42
![Page 4: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/4.jpg)
Motivation
Conventional type systems: ML, Java, . . .Tractable and easy to useLimited expressive power
Refined type systems:Tractable and easy to useBetter expressive power
Fully dependent type systems: Nuprl, . . .UndecidableExtremely expressive
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.3/42
![Page 5: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/5.jpg)
Push the envelope
The goal of the Triple Project: create refined typesystems.
The present work: Persistent refinements ofalgebraic datatypes
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.4/42
![Page 6: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/6.jpg)
Type Assignment
A type assignment system a la CurryTerms do not contain typesUndecidable
A bidirectional systemTerms contain some type annotationsTwo judgments: inference e ↑ A, checking e ↓ A.
This paper: Type assignment only
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.5/42
![Page 7: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/7.jpg)
Property Types
Some types build values
Example: tuples
Others talk about valuesExample: parametric polymorphism ∀α. α → α
∀ describing behavior of the identity fn
We call the latter property types
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.6/42
![Page 8: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/8.jpg)
Property Types
Some types build valuesExample: tuples
Others talk about valuesExample: parametric polymorphism ∀α. α → α
∀ describing behavior of the identity fn
We call the latter property types
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.6/42
![Page 9: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/9.jpg)
Property Types
Some types build valuesExample: tuples
Others talk about values
Example: parametric polymorphism ∀α. α → α
∀ describing behavior of the identity fn
We call the latter property types
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.6/42
![Page 10: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/10.jpg)
Property Types
Some types build valuesExample: tuples
Others talk about valuesExample: parametric polymorphism ∀α. α → α
∀ describing behavior of the identity fn
We call the latter property types
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.6/42
![Page 11: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/11.jpg)
Property Types
Some types build valuesExample: tuples
Others talk about valuesExample: parametric polymorphism ∀α. α → α
∀ describing behavior of the identity fn
We call the latter property types
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.6/42
![Page 12: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/12.jpg)
Property Types
Some types build valuesExample: tuples
Others talk about valuesExample: parametric polymorphism ∀α. α → α
∀ describing behavior of the identity fn
We call the latter property types
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.6/42
![Page 13: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/13.jpg)
Property Types
In our system:
δ(i): Datasort and index refinement∧: Intersection: v : A ∧ B means v has type A andtype B
>>: Greatest type (0-ary ∧)Π: Universal quantifier over indices (infinitary ∧)∨: Union: v : A ∨ B means v has type A or type B
⊥⊥: Empty type (0-ary ∨)Σ: Existential quantifier over indices (infinitary ∨)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.7/42
![Page 14: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/14.jpg)
Property Types
In our system:δ(i): Datasort and index refinement
∧: Intersection: v : A ∧ B means v has type A andtype B
>>: Greatest type (0-ary ∧)Π: Universal quantifier over indices (infinitary ∧)∨: Union: v : A ∨ B means v has type A or type B
⊥⊥: Empty type (0-ary ∨)Σ: Existential quantifier over indices (infinitary ∨)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.7/42
![Page 15: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/15.jpg)
Property Types
In our system:δ(i): Datasort and index refinement∧: Intersection: v : A ∧ B means v has type A andtype B
>>: Greatest type (0-ary ∧)Π: Universal quantifier over indices (infinitary ∧)∨: Union: v : A ∨ B means v has type A or type B
⊥⊥: Empty type (0-ary ∨)Σ: Existential quantifier over indices (infinitary ∨)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.7/42
![Page 16: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/16.jpg)
Property Types
In our system:δ(i): Datasort and index refinement∧: Intersection: v : A ∧ B means v has type A andtype B
>>: Greatest type (0-ary ∧)
Π: Universal quantifier over indices (infinitary ∧)∨: Union: v : A ∨ B means v has type A or type B
⊥⊥: Empty type (0-ary ∨)Σ: Existential quantifier over indices (infinitary ∨)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.7/42
![Page 17: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/17.jpg)
Property Types
In our system:δ(i): Datasort and index refinement∧: Intersection: v : A ∧ B means v has type A andtype B
>>: Greatest type (0-ary ∧)Π: Universal quantifier over indices (infinitary ∧)
∨: Union: v : A ∨ B means v has type A or type B
⊥⊥: Empty type (0-ary ∨)Σ: Existential quantifier over indices (infinitary ∨)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.7/42
![Page 18: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/18.jpg)
Property Types
In our system:δ(i): Datasort and index refinement∧: Intersection: v : A ∧ B means v has type A andtype B
>>: Greatest type (0-ary ∧)Π: Universal quantifier over indices (infinitary ∧)∨: Union: v : A ∨ B means v has type A or type B
⊥⊥: Empty type (0-ary ∨)Σ: Existential quantifier over indices (infinitary ∨)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.7/42
![Page 19: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/19.jpg)
Property Types
In our system:δ(i): Datasort and index refinement∧: Intersection: v : A ∧ B means v has type A andtype B
>>: Greatest type (0-ary ∧)Π: Universal quantifier over indices (infinitary ∧)∨: Union: v : A ∨ B means v has type A or type B
⊥⊥: Empty type (0-ary ∨)
Σ: Existential quantifier over indices (infinitary ∨)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.7/42
![Page 20: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/20.jpg)
Property Types
In our system:δ(i): Datasort and index refinement∧: Intersection: v : A ∧ B means v has type A andtype B
>>: Greatest type (0-ary ∧)Π: Universal quantifier over indices (infinitary ∧)∨: Union: v : A ∨ B means v has type A or type B
⊥⊥: Empty type (0-ary ∨)Σ: Existential quantifier over indices (infinitary ∨)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.7/42
![Page 21: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/21.jpg)
Language
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.8/42
![Page 22: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/22.jpg)
Language + Initial Typing
A, B, C, D ::= 1 | A → B
e ::= x | f | () | λx. e | e1(e2) | fix f. e
B1 ≤ A1 A2 ≤ B2
A1 → A2 ≤ B1 → B2(→)
1 ≤ 1(1)
Γ(x) = A
Γ ` x : A(var)
Γ(f) = A
Γ ` f : A(fixvar)
Γ ` e : A A ≤ B
Γ ` e : B(sub)
Γ ` e1 : A → B Γ ` e2 : A
Γ ` e1(e2) : B(→E) Γ, f:A ` e : A
Γ ` fix f. e : A(fix)
Γ, x:A ` e : BΓ ` λx. e : A → B
(→I)Γ ` () : 1
(1I)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.9/42
![Page 23: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/23.jpg)
cbv Semantics
Values v ::= x | () | λx. e
Evaluation contexts E ::= [] | E(e) | v(E)
e ′ 7→R e ′′
E[e ′] 7→ E[e ′′]
(λx. e) v 7→R [v/x] e
fix f. e 7→R [fix f. e / f] e
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.10/42
![Page 24: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/24.jpg)
Key Properties
A practical type system should satisfy
Preservation: If ` e : A and e 7→ e ′ then ` e ′ : A.
Progress: If ` e : A then e is a value or ∃e ′. e 7→ e ′.
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.11/42
![Page 25: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/25.jpg)
Datasort Refinements
a.k.a. refinement types (Freeman, Pfenning, Davies)
Refine an algebraic datatype by a datasort δ
Example: Lists of integersNil : 1 → list
Cons : int ∗ list → list
Nil : 1 → even
Cons : (int ∗ odd → even)
∧ (int ∗ even → odd)
∧ (int ∗ list → list)
δ : list
���>
oddZ
ZZ}
even
Intersections essential
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.12/42
![Page 26: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/26.jpg)
Index Refinements
a.k.a. dependent types restricted to a decidableconstraint domain (Xi & Pfenning)
Refine an algebraic datatype by an index
Indices drawn from any decidable constraint domain,here N
Example: Lists indexed by their lengthNil : 1 → list
Cons : int ∗ list → list
Nil : 1 → list(0)
Cons : Πa:N . int∗list(a) → list(a + 1)
Example:append : Πa:N . Πb:N . list(a) ∗ list(b) → list(a+b)
Universal quantifier Π essential
Existential quantifier Σ also essential
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.13/42
![Page 27: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/27.jpg)
Intersection Types
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.14/42
![Page 28: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/28.jpg)
Typing Intersections
Typing:
Γ ` e : A1 ∧ A2
Γ ` e : A1(∧E1)
Γ ` e : A1 ∧ A2
Γ ` e : A2(∧E2)
Γ ` e : A1 Γ ` e : A2
Γ ` e : A1 ∧ A2(∧I)
(∧I) unsound with mutable references.
Γ ` v : A1 Γ ` v : A2
Γ ` v : A1 ∧ A2(∧I)
The fix: a value restriction [Davies & Pfenning ’00].
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.15/42
![Page 29: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/29.jpg)
Typing Intersections
Typing:
Γ ` e : A1 ∧ A2
Γ ` e : A1(∧E1)
Γ ` e : A1 ∧ A2
Γ ` e : A2(∧E2)
Γ ` e : A1 Γ ` e : A2
Γ ` e : A1 ∧ A2(∧I)
(∧I) unsound with mutable references.
Γ ` v : A1 Γ ` v : A2
Γ ` v : A1 ∧ A2(∧I)
The fix: a value restriction [Davies & Pfenning ’00].
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.15/42
![Page 30: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/30.jpg)
Typing Intersections
Typing:
Γ ` e : A1 ∧ A2
Γ ` e : A1(∧E1)
Γ ` e : A1 ∧ A2
Γ ` e : A2(∧E2)
Γ ` e : A1 Γ ` e : A2
Γ ` e : A1 ∧ A2(∧I)
(∧I) unsound with mutable references.
Γ `
v
: A1 Γ `
v
: A2
Γ `
v
: A1 ∧ A2(∧I)
The fix: a value restriction [Davies & Pfenning ’00].
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.15/42
![Page 31: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/31.jpg)
Typing Intersections
Typing:
Γ ` e : A1 ∧ A2
Γ ` e : A1(∧E1)
Γ ` e : A1 ∧ A2
Γ ` e : A2(∧E2)
Γ ` e : A1 Γ ` e : A2
Γ ` e : A1 ∧ A2(∧I)
(∧I) unsound with mutable references.
Γ ` v : A1 Γ ` v : A2
Γ ` v : A1 ∧ A2(∧I)
The fix: a value restriction [Davies & Pfenning ’00].
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.15/42
![Page 32: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/32.jpg)
Indefinite Types
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.16/42
![Page 33: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/33.jpg)
Indefinite Types: Motivation
filter : (int→bool) → list → list
filter : Πa:N . (int→bool) → list(a) → list( )
filter : Πa:N . (int→bool) → list(a) → (Σb:N . list(b))
Σb:N . B quantifies existentially over b in B
[Xi & Pfenning]
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.17/42
![Page 34: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/34.jpg)
Indefinite Types: Motivation
filter : (int→bool) → list → list
filter : Πa:N . (int→bool) → list(a) → list( )
filter : Πa:N . (int→bool) → list(a) → (Σb:N . list(b))
Σb:N . B quantifies existentially over b in B
[Xi & Pfenning]
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.17/42
![Page 35: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/35.jpg)
Indefinite Types: Motivation
Definitely need Σ
The binary analogue of Σ is the union type ∨
Need ∨? Possibly just a convenience
Issues similar for both, but easier to talk about ∨
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.18/42
![Page 36: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/36.jpg)
Union Types
Introduction rules straightforward:
Γ ` e : AΓ ` e : A ∨ B
(∨I1) Γ ` e : BΓ ` e : A ∨ B
(∨I2)
Elimination rule?
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.19/42
![Page 37: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/37.jpg)
Union Types
Introduction rules straightforward:
Γ ` e : AΓ ` e : A ∨ B
(∨I1) Γ ` e : BΓ ` e : A ∨ B
(∨I2)
Elimination rule?
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.19/42
![Page 38: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/38.jpg)
Rough Road
Recall: for ∧, introduction rule (∧I) was tricky
Duality suggests (∨E) will be interesting too
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.20/42
![Page 39: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/39.jpg)
Rough Road
Recall: for ∧, introduction rule (∧I) was tricky
Duality suggests (∨E) will be interesting too
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.20/42
![Page 40: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/40.jpg)
∨ Elimination
Want to reason by cases: For x : A ∨ B, show forx : A and for x : B.
Substitution approach (e.g. [MacQueen et al.’86]),reminiscent of natural deduction:
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Suppose Γ ` h : (A → C) ∧ (B → C), Γ ` v : A ∨ B
Γ ` v : A ∨ B Γ, x:A ` h x : C Γ, x:B ` h x : CΓ ` h v : C
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.21/42
![Page 41: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/41.jpg)
∨ Elimination
Want to reason by cases: For x : A ∨ B, show forx : A and for x : B.
Substitution approach (e.g. [MacQueen et al.’86]),reminiscent of natural deduction:
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Suppose Γ ` h : (A → C) ∧ (B → C), Γ ` v : A ∨ B
Γ ` v : A ∨ B Γ, x:A ` h x : C Γ, x:B ` h x : CΓ ` h v : C
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.21/42
![Page 42: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/42.jpg)
∨ Elimination
Want to reason by cases: For x : A ∨ B, show forx : A and for x : B.
Substitution approach (e.g. [MacQueen et al.’86]),reminiscent of natural deduction:
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Suppose Γ ` h : (A → C) ∧ (B → C), Γ ` v : A ∨ B
Γ ` v : A ∨ B Γ, x:A ` h x : C Γ, x:B ` h x : CΓ ` h v : C
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.21/42
![Page 43: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/43.jpg)
∨ Elimination
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Consider a nondeterministic choice e1 ⊕⊕ e2:
e1 ⊕⊕ e2 7→ e1 e1 ⊕⊕ e2 7→ e2
Suppose Γ ` g : (A → A → C) ∧ (B → B → C),Γ ` y : A, Γ ` z : B.
Γ ` y ⊕⊕ z : A ∨ B Γ, x:A ` g x x : C Γ, x:B ` g x x : C
Γ ` g (y ⊕⊕ z) (y ⊕⊕ z) : C
g (y ⊕⊕ z) (y ⊕⊕ z) 7→ g y (y ⊕⊕ z) 7→ g y z
Unsound whenever a term evaluates to more thanone value
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.22/42
![Page 44: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/44.jpg)
∨ Elimination
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Consider a nondeterministic choice e1 ⊕⊕ e2:
e1 ⊕⊕ e2 7→ e1 e1 ⊕⊕ e2 7→ e2
Suppose Γ ` g : (A → A → C) ∧ (B → B → C),Γ ` y : A, Γ ` z : B.
Γ ` y ⊕⊕ z : A ∨ B Γ, x:A ` g x x : C Γ, x:B ` g x x : C
Γ ` g (y ⊕⊕ z) (y ⊕⊕ z) : C
g (y ⊕⊕ z) (y ⊕⊕ z) 7→ g y (y ⊕⊕ z) 7→ g y z
Unsound whenever a term evaluates to more thanone value
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.22/42
![Page 45: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/45.jpg)
∨ Elimination
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Consider a nondeterministic choice e1 ⊕⊕ e2:
e1 ⊕⊕ e2 7→ e1 e1 ⊕⊕ e2 7→ e2
Suppose Γ ` g : (A → A → C) ∧ (B → B → C),Γ ` y : A, Γ ` z : B.
Γ ` y ⊕⊕ z : A ∨ B Γ, x:A ` g x x : C Γ, x:B ` g x x : C
Γ ` g (y ⊕⊕ z) (y ⊕⊕ z) : C
g (y ⊕⊕ z) (y ⊕⊕ z) 7→ g y (y ⊕⊕ z) 7→ g y z
Unsound whenever a term evaluates to more thanone value
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.22/42
![Page 46: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/46.jpg)
∨ Elimination
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Consider a nondeterministic choice e1 ⊕⊕ e2:
e1 ⊕⊕ e2 7→ e1 e1 ⊕⊕ e2 7→ e2
Suppose Γ ` g : (A → A → C) ∧ (B → B → C),Γ ` y : A, Γ ` z : B.
Γ ` y ⊕⊕ z : A ∨ B Γ, x:A ` g x x : C Γ, x:B ` g x x : C
Γ ` g (y ⊕⊕ z) (y ⊕⊕ z) : C
g (y ⊕⊕ z) (y ⊕⊕ z) 7→ g y (y ⊕⊕ z) 7→ g y z
Unsound whenever a term evaluates to more thanone value
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.22/42
![Page 47: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/47.jpg)
∨ Elimination
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Restrict to exactly one occurrence of e ′?
Can fail if e ′ inside a λ (see paper)
Restrict e ′ to a value? [van Bakel ’99]Sound—but still must guess occurrences of e ′
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.23/42
![Page 48: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/48.jpg)
∨ Elimination
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Restrict to exactly one occurrence of e ′?Can fail if e ′ inside a λ (see paper)
Restrict e ′ to a value? [van Bakel ’99]Sound—but still must guess occurrences of e ′
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.23/42
![Page 49: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/49.jpg)
∨ Elimination
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Restrict to exactly one occurrence of e ′?Can fail if e ′ inside a λ (see paper)
Restrict e ′ to a value? [van Bakel ’99]
Sound—but still must guess occurrences of e ′
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.23/42
![Page 50: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/50.jpg)
∨ Elimination
Γ ` e ′ : A ∨ B
Γ, x:A ` e : C
Γ, x:B ` e : C
Γ ` [e ′/x] e : C
Restrict to exactly one occurrence of e ′?Can fail if e ′ inside a λ (see paper)
Restrict e ′ to a value? [van Bakel ’99]Sound—but still must guess occurrences of e ′
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.23/42
![Page 51: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/51.jpg)
∨ Elimination: Our Solution
Γ ` e ′ : A ∨ B
Γ, x:A ` E[x] : C
Γ, x:B ` E[x] : C
Γ ` E[e ′] : C(∨E)
Exactly one e ′, in evaluation position
So e ′ is the next thing to be evaluated
Remainder of computation (E) on the result of e ′
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.24/42
![Page 52: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/52.jpg)
∨ Elimination: Our Solution
Γ ` e ′ : A ∨ B
Γ, x:A ` E[x] : C
Γ, x:B ` E[x] : C
Γ ` E[e ′] : C(∨E)
Exactly one e ′, in evaluation position
So e ′ is the next thing to be evaluated
Remainder of computation (E) on the result of e ′
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.24/42
![Page 53: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/53.jpg)
∨ Elimination: Our Solution
Γ ` e ′ : A ∨ B
Γ, x:A ` E[x] : C
Γ, x:B ` E[x] : C
Γ ` E[e ′] : C(∨E)
Exactly one e ′, in evaluation position
So e ′ is the next thing to be evaluated
Remainder of computation (E) on the result of e ′
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.24/42
![Page 54: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/54.jpg)
The Empty Type ⊥⊥
⊥⊥ is the empty or void type
⊥⊥ ≤ A(⊥⊥L)
Elimination rule: by analogy with (∨E)Γ ` e ′ : ⊥
Γ ` E[e ′] : C(⊥⊥E)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.25/42
![Page 55: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/55.jpg)
A Generalization?
Must we restrict the rules to an evaluation context?
Or could we also allow cases where e ′ must beevaluated exactly once but might not be in evaluationposition?
Γ ` e ′ : ⊥⊥ e ′ eval’d exactly once in e
Γ ` e : C
. . . let ω = (fix f. f). Then ω : ⊥⊥.Γ ` ω : ⊥⊥
Γ ` (()())ω : C
But ()() is not a value and does not step
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.26/42
![Page 56: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/56.jpg)
A Generalization?
Must we restrict the rules to an evaluation context?
Or could we also allow cases where e ′ must beevaluated exactly once but might not be in evaluationposition?
Γ ` e ′ : ⊥⊥ e ′ eval’d exactly once in e
Γ ` e : C
. . . let ω = (fix f. f). Then ω : ⊥⊥.Γ ` ω : ⊥⊥
Γ ` (()())ω : C
But ()() is not a value and does not step
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.26/42
![Page 57: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/57.jpg)
A Generalization?
Must we restrict the rules to an evaluation context?
Or could we also allow cases where e ′ must beevaluated exactly once but might not be in evaluationposition?
Γ ` e ′ : ⊥⊥ e ′ eval’d exactly once in e
Γ ` e : C
. . . let ω = (fix f. f). Then ω : ⊥⊥.Γ ` ω : ⊥⊥
Γ ` (()())ω : C
But ()() is not a value and does not step
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.26/42
![Page 58: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/58.jpg)
A Generalization?
Must we restrict the rules to an evaluation context?
Or could we also allow cases where e ′ must beevaluated exactly once but might not be in evaluationposition?
Γ ` e ′ : ⊥⊥ e ′ eval’d exactly once in e
Γ ` e : C
. . . let ω = (fix f. f). Then ω : ⊥⊥.Γ ` ω : ⊥⊥
Γ ` (()())ω : C
But ()() is not a value and does not step
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.26/42
![Page 59: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/59.jpg)
Type Safety
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.27/42
![Page 60: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/60.jpg)
Type Safety
Γ ` e ′ : A ∨ B
Γ, x:A ` E[x] : C
Γ, x:B ` E[x] : C
Γ ` E[e ′] : C(∨E)
X
Preservation and progress hold withδ, i, ∧,>>, Π, ∨,⊥⊥, Σ
Lemma: Values always have definite types.6` v : ⊥⊥
If ` v : A ∨ B then ` v : A or ` v : B
If ` v : Σa:N . A then ` v : [i/a] A for some i
Above: a special case of the actual lemma
(Fully written out for δ, i, ∧, Π in [Dunfield ’02])
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.28/42
![Page 61: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/61.jpg)
Closely Related Work
Ongoing workδ, i, ∧, Π, >>, ∨, Σ, ⊥⊥; ↑↓
?
This paper*δ, i, ∧, Π, >>, ∨, Σ, ⊥⊥; :
?
Dunfield ’02δ, i, ∧, Π; ↑↓
��
�
Xi ’98, ’99*, ’00i, Π, Σ; ↑↓
@@
@R
Davies ’97, ’00*δ, ∧; ↑↓
* & PfenningType assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.29/42
![Page 62: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/62.jpg)
Related Work
[Coppo et al.’81]: ∧ can characterize normal forms(termination); hence undecidable
[Reynolds ’96]: FORSYTHE with ∧ (& typeannotations)
[Pierce ’91]: Language with ∧, ∨, syntactic markers
[Barbanera et al.’95]: With unrestricted ∨-elim rule,types not preserved under β-reduction
[Wells et al.’02], [Palsberg & Pavlopoulou ’01]: ∧, ∨
for control flow analysis
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.30/42
![Page 63: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/63.jpg)
Conclusion
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.31/42
![Page 64: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/64.jpg)
Summary
Goal: express more invariants
Two especially useful refinements already developed:Datasort refinementsIndex refinements
Refinements motivate ∧, ∨, Π, Σ
(∧I): Value restriction
(∨E): Eval. context restriction
Type safety
The present system: Undecidable, hence impractical
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.32/42
![Page 65: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/65.jpg)
Future Work
Bidirectional formulation X
Let-normal form X
Mutable references
Implementation
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.33/42
![Page 66: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/66.jpg)
Acknowledgments
National Science Foundation: CCR-0204248: TypeRefinements; 0121633: ITR/SY+SI: LanguageTechnology for Trustless Software Dissemination;Graduate Research Fellowship
Feedback on the paper: Brigitte Pientka and theanonymous referees
Feedback on the talk: Aleksey Kliger, Stephen Magill,Jonathan Moody, Frank Pfenning
“ ”: Henrik Christian Grove, available at a CTANmirror near you
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.34/42
![Page 67: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/67.jpg)
The End
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.35/42
![Page 68: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/68.jpg)
Intersections: Subtyping
Subtyping:A ≤ B1 A ≤ B2
A ≤ B1 ∧ B2(∧R)
A1 ≤ B
A1 ∧ A2 ≤ B(∧L1)
A2 ≤ B
A1 ∧ A2 ≤ B(∧L2)
Distributivity?
(A → B) ∧ (A → B ′) ≤ A → (B ∧ B ′)
Again unsound with mutable references. [Davies &Pfenning ’00]
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.36/42
![Page 69: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/69.jpg)
Intersections: Subtyping
Subtyping:A ≤ B1 A ≤ B2
A ≤ B1 ∧ B2(∧R)
A1 ≤ B
A1 ∧ A2 ≤ B(∧L1)
A2 ≤ B
A1 ∧ A2 ≤ B(∧L2)
Distributivity?
(A → B) ∧ (A → B ′) ≤ A → (B ∧ B ′)
Again unsound with mutable references. [Davies &Pfenning ’00]
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.36/42
![Page 70: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/70.jpg)
Intersections: Subtyping
Subtyping:A ≤ B1 A ≤ B2
A ≤ B1 ∧ B2(∧R)
A1 ≤ B
A1 ∧ A2 ≤ B(∧L1)
A2 ≤ B
A1 ∧ A2 ≤ B(∧L2)
Distributivity?
(A → B) ∧ (A → B ′) ≤ A → (B ∧ B ′)
Again unsound with mutable references. [Davies &Pfenning ’00]
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.36/42
![Page 71: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/71.jpg)
Unions: Subtyping
Subtyping for ∨ just the dual of ∧:
A1 ≤ B A2 ≤ B
A1∨A2 ≤ B(∨L)
A ≤ B1
A ≤ B1∨B2(∨R1)
A ≤ B2
A ≤ B1∨B2(∨R2)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.37/42
![Page 72: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/72.jpg)
Unions: Subtyping
Subtyping for ∨ just the dual of ∧:
A1 ≤ B A2 ≤ B
A1∨A2 ≤ B(∨L)
A ≤ B1
A ≤ B1∨B2(∨R1)
A ≤ B2
A ≤ B1∨B2(∨R2)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.37/42
![Page 73: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/73.jpg)
Formulating Refinements
P ::= ⊥⊥ | i.= j | . . .
Γ ::= · | Γ, x:A | Γ, a:γ | Γ, P
e ::= . . . | c(e) | case e of ms
v ::= . . . | c(v)
E ::= . . . | c(E) | case E of ms
Atomic subtypingδ1 � δ2 Γ ` i
.= j
Γ ` δ1(i) ≤ δ2(j)(δ)
Γ ` c : A → δ(i) Γ ` e : A
Γ ` c(e) : δ(i)(δI)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.38/42
![Page 74: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/74.jpg)
Formulating Refinements
P ::= ⊥⊥ | i.= j | . . .
Γ ::= · | Γ, x:A | Γ, a:γ | Γ, P
e ::= . . . | c(e) | case e of ms
v ::= . . . | c(v)
E ::= . . . | c(E) | case E of ms
Atomic subtypingδ1 � δ2 Γ ` i
.= j
Γ ` δ1(i) ≤ δ2(j)(δ)
Γ ` c : A → δ(i) Γ ` e : A
Γ ` c(e) : δ(i)(δI)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.38/42
![Page 75: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/75.jpg)
Formulating Refinements
P ::= ⊥⊥ | i.= j | . . .
Γ ::= · | Γ, x:A | Γ, a:γ | Γ, P
e ::= . . . | c(e) | case e of ms
v ::= . . . | c(v)
E ::= . . . | c(E) | case E of ms
Atomic subtypingδ1 � δ2 Γ ` i
.= j
Γ ` δ1(i) ≤ δ2(j)(δ)
Γ ` c : A → δ(i) Γ ` e : A
Γ ` c(e) : δ(i)(δI)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.38/42
![Page 76: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/76.jpg)
Formulating Refinements
Atomic subtypingδ1 � δ2 Γ ` i
.= j
Γ ` δ1(i) ≤ δ2(j)(δ)
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.39/42
![Page 77: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/77.jpg)
Evaluation Order
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.40/42
![Page 78: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/78.jpg)
Evaluation Order
Binary and 0-ary indefinite type elim rules:
Γ ` e ′ : A ∨ B
Γ, x:A ` E[x] : C
Γ, x:B ` E[x] : C
Γ ` E[e ′] : C(∨E) Γ ` e ′ : ⊥
Γ ` E[e ′] : C(⊥⊥E)
A corresponding unary rule?Γ ` e ′ : A Γ, x:A ` E[x] : C
Γ ` E[e ′] : C(direct)
Actually a derivable rule: (∨E) with A ∨ A
But not derivable in a bidirectional system
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.41/42
![Page 79: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/79.jpg)
Evaluation Order
Binary and 0-ary indefinite type elim rules:
Γ ` e ′ : A ∨ B
Γ, x:A ` E[x] : C
Γ, x:B ` E[x] : C
Γ ` E[e ′] : C(∨E) Γ ` e ′ : ⊥
Γ ` E[e ′] : C(⊥⊥E)
A corresponding unary rule?Γ ` e ′ : A Γ, x:A ` E[x] : C
Γ ` E[e ′] : C(direct)
Actually a derivable rule: (∨E) with A ∨ A
But not derivable in a bidirectional system
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.41/42
![Page 80: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/80.jpg)
Evaluation Order
Binary and 0-ary indefinite type elim rules:
Γ ` e ′ : A ∨ B
Γ, x:A ` E[x] : C
Γ, x:B ` E[x] : C
Γ ` E[e ′] : C(∨E) Γ ` e ′ : ⊥
Γ ` E[e ′] : C(⊥⊥E)
A corresponding unary rule?Γ ` e ′ : A Γ, x:A ` E[x] : C
Γ ` E[e ′] : C(direct)
Actually a derivable rule: (∨E) with A ∨ A
But not derivable in a bidirectional system
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.41/42
![Page 81: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/81.jpg)
Evaluation Order
Binary and 0-ary indefinite type elim rules:
Γ ` e ′ : A ∨ B
Γ, x:A ` E[x] : C
Γ, x:B ` E[x] : C
Γ ` E[e ′] : C(∨E) Γ ` e ′ : ⊥
Γ ` E[e ′] : C(⊥⊥E)
A corresponding unary rule?Γ ` e ′ : A Γ, x:A ` E[x] : C
Γ ` E[e ′] : C(direct)
Actually a derivable rule: (∨E) with A ∨ A
But not derivable in a bidirectional system
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.41/42
![Page 82: Type assignment for intersections and unions in call-by-value … · in call-by-value languages Joshua Duneld and Frank Pfenning Triple Project Carnegie Mellon University 8 April](https://reader033.vdocuments.mx/reader033/viewer/2022060909/60a407139c7b7c0d35454319/html5/thumbnails/82.jpg)
Evaluation OrderΓ ` e ′ : A Γ, x:A ` E[x] : C
Γ ` E[e ′] : C(direct)
Rule needed so that Π’s can be instantiated withexistential Σ index variables
Problem first recognized by Xi
Formulated a translation to let-normal form
Added “good” programs, but removed them too
Current work: a sound, complete let-normaltranslation
Type assignment for intersections and unions in call-by-value languages—FOSSACS ’03 – p.42/42