gradual typing with union and intersection types · gradual typing with union and intersection...
TRANSCRIPT
![Page 1: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/1.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Gradual Typing with Union and Intersection Types
Giuseppe Castagna, Victor Lanvin
ICFP ’17
September 6, 2017
1 / 14
![Page 2: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/2.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Outline
1 Motivating Example
2 Types and Subtyping
3 Function Types and Operators
4 Conclusion
1 / 14
![Page 3: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/3.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Motivating Example (1/3)
[Siek and Vachharajani, 2008]
let succ : Int -> Int = ...let not : Bool -> Bool = ...
let f (condition : Bool) (x :
?
) :
?
=if condition then
succ xelse
not x
→ Cannot be typed with simple types, but valid with gradual types.→ What if we apply it to a string?
2 / 14
![Page 4: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/4.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Motivating Example (1/3)
[Siek and Vachharajani, 2008]
let succ : Int -> Int = ...let not : Bool -> Bool = ...
let f (condition : Bool) (x : ?) : ? =if condition then
succ xelse
not x
→ Cannot be typed with simple types, but valid with gradual types.
→ What if we apply it to a string?
2 / 14
![Page 5: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/5.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Motivating Example (1/3)
[Siek and Vachharajani, 2008]
let succ : Int -> Int = ...let not : Bool -> Bool = ...
let f (condition : Bool) (x : ?) : ? =if condition then
succ xelse
not x
→ Cannot be typed with simple types, but valid with gradual types.→ What if we apply it to a string?
2 / 14
![Page 6: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/6.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Motivating Example (2/3)
Set-theoretic version:
let f (condition : Bool) (x : (Int | Bool)): (Int | Bool) =
if condition thenif x ∈ Int then succ x else assert false
elseif x ∈ Bool then not x else assert false
→ Syntactically heavy, but safe
3 / 14
![Page 7: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/7.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Motivating Example (2/3)
Set-theoretic version:
let f (condition : Bool) (x : (Int | Bool)): (Int | Bool) =
if condition thenif x ∈ Int then succ x else assert false
elseif x ∈ Bool then not x else assert false
→ Syntactically heavy, but safe
3 / 14
![Page 8: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/8.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Motivating Example (3/3)
Mixing the two:
let f (condition : Bool) (x : (Int | Bool) & ?): (Int | Bool) =
if condition thensucc x
elsenot x
→ Cannot be applied to something else than an integer or aboolean, and has a precise return type→ Syntactically straightforward
4 / 14
![Page 9: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/9.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Motivating Example (3/3)
Mixing the two:
let f (condition : Bool) (x : (Int | Bool) & ?): (Int | Bool) =
if condition thensucc x
elsenot x
→ Cannot be applied to something else than an integer or aboolean, and has a precise return type→ Syntactically straightforward
4 / 14
![Page 10: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/10.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Summary of the Motivations
– Gradualization of single expressions is sometimes too coarse
– Set-theoretic types are powerful but syntactically heavy (noreconstruction)
Mixing the two would:
– Make the transition between dynamic types and static typessmoother
– Reduce the syntactic overhead of set-theoretic types
5 / 14
![Page 11: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/11.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Summary of the Motivations
– Gradualization of single expressions is sometimes too coarse
– Set-theoretic types are powerful but syntactically heavy (noreconstruction)
Mixing the two would:
– Make the transition between dynamic types and static typessmoother
– Reduce the syntactic overhead of set-theoretic types
5 / 14
![Page 12: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/12.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Outline
1 Motivating Example
2 Types and Subtyping
3 Function Types and Operators
4 Conclusion
5 / 14
![Page 13: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/13.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Syntax
t ∈ STypes ::= b | t → t | t ∨ t | t ∧ t | ¬t | Empty | Any
τ ∈ GTypes ::= ? | b | τ → τ | τ ∨ τ | τ ∧ τ | ¬t | Empty | Any
Note: ? 6= Any
Any = unknown type, explicitly deconstructed? = unknown type, implicitly deconstructed
6 / 14
![Page 14: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/14.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Syntax
t ∈ STypes ::= b | t → t | t ∨ t | t ∧ t | ¬t | Empty | Any
τ ∈ GTypes ::= ? | b | τ → τ | τ ∨ τ | τ ∧ τ | ¬t | Empty | Any
Note: ? 6= Any
Any = unknown type, explicitly deconstructed? = unknown type, implicitly deconstructed
6 / 14
![Page 15: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/15.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Concretization
First idea: apply AGT [Garcia et al., 2016]
We define a concretization function γ : GTypes→ P(STypes).
γ(?) = STypesγ(τ1 ∨ τ2) = {t1 ∨ t2 | ti ∈ γ(τi )}γ(τ1 → τ2) = {t1 → t2 | ti ∈ γ(τi )}
γ(b) = {b}etc...
For example,
γ((?→ Int)∧ ?) = {(t → Int) ∧ t ′ | (t, t ′) ∈ STypes2}
7 / 14
![Page 16: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/16.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Concretization
First idea: apply AGT [Garcia et al., 2016]
We define a concretization function γ : GTypes→ P(STypes).
γ(?) = STypesγ(τ1 ∨ τ2) = {t1 ∨ t2 | ti ∈ γ(τi )}γ(τ1 → τ2) = {t1 → t2 | ti ∈ γ(τi )}
γ(b) = {b}etc...
For example,
γ((?→ Int)∧ ?) = {(t → Int) ∧ t ′ | (t, t ′) ∈ STypes2}
7 / 14
![Page 17: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/17.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Concretization
First idea: apply AGT [Garcia et al., 2016]
We define a concretization function γ : GTypes→ P(STypes).
γ(?) = STypesγ(τ1 ∨ τ2) = {t1 ∨ t2 | ti ∈ γ(τi )}γ(τ1 → τ2) = {t1 → t2 | ti ∈ γ(τi )}
γ(b) = {b}etc...
For example,
γ((?→ Int)∧ ?) = {(t → Int) ∧ t ′ | (t, t ′) ∈ STypes2}
7 / 14
![Page 18: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/18.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Subtyping (1/2)
Consistent subtyping [Garcia et al., 2016]
σ ≤̃ τ ⇐⇒ ∃(s, t) ∈ γ(σ)× γ(τ), s ≤ t
However, we can show the existence of “extremal” concretizations:
∀t ∈ γ(τ), τ⇓ ≤ t ≤ τ⇑
(?→?)⇓ = (Any→ Empty) (?→?)⇑ = (Empty→ Any)
8 / 14
![Page 19: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/19.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Subtyping (1/2)
Consistent subtyping [Garcia et al., 2016]
σ ≤̃ τ ⇐⇒ ∃(s, t) ∈ γ(σ)× γ(τ), s ≤ t
However, we can show the existence of “extremal” concretizations:
∀t ∈ γ(τ), τ⇓ ≤ t ≤ τ⇑
(?→?)⇓ = (Any→ Empty) (?→?)⇑ = (Empty→ Any)
8 / 14
![Page 20: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/20.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Subtyping (1/2)
Consistent subtyping [Garcia et al., 2016]
σ ≤̃ τ ⇐⇒ ∃(s, t) ∈ γ(σ)× γ(τ), s ≤ t
However, we can show the existence of “extremal” concretizations:
∀t ∈ γ(τ), τ⇓ ≤ t ≤ τ⇑
(?→?)⇓ = (Any→ Empty) (?→?)⇑ = (Empty→ Any)
8 / 14
![Page 21: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/21.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Subtyping (2/2)
Consistent subtyping
σ ≤̃ τ ⇐⇒ σ⇓ ≤ τ⇑
=⇒ Consistent subtyping reduces in linear time to semanticsubtyping!
Note: emphasizes the fact that consistent subtyping is nottransitive.
9 / 14
![Page 22: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/22.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Subtyping (2/2)
Consistent subtyping
σ ≤̃ τ ⇐⇒ σ⇓ ≤ τ⇑
=⇒ Consistent subtyping reduces in linear time to semanticsubtyping!
Note: emphasizes the fact that consistent subtyping is nottransitive.
9 / 14
![Page 23: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/23.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Subtyping (2/2)
Consistent subtyping
σ ≤̃ τ ⇐⇒ σ⇓ ≤ τ⇑
=⇒ Consistent subtyping reduces in linear time to semanticsubtyping!
Note: emphasizes the fact that consistent subtyping is nottransitive.
9 / 14
![Page 24: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/24.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty})
=
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨
?
α({Int ∨ Bool, Bool ∨ Int}) =
10 / 14
![Page 25: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/25.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty})
=
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨
?
α({Int ∨ Bool, Bool ∨ Int}) =
10 / 14
![Page 26: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/26.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty}) =
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨
?
α({Int ∨ Bool, Bool ∨ Int}) =
10 / 14
![Page 27: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/27.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty}) =
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨
?
α({Int ∨ Bool, Bool ∨ Int}) =
10 / 14
![Page 28: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/28.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty})
=
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})
= Int ∨
?
α({Int ∨ Bool, Bool ∨ Int}) =
10 / 14
![Page 29: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/29.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty})
=
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨
?
α({Int ∨ Bool, Bool ∨ Int}) =
10 / 14
![Page 30: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/30.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty})
=
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨ ?
α({Int ∨ Bool, Bool ∨ Int}) =
10 / 14
![Page 31: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/31.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty})
=
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨ ?
α({Int ∨ Bool, Bool ∨ Int}) = ???
10 / 14
![Page 32: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/32.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty})
=
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨ ?
α({Int ∨ Bool, Bool ∨ Int}) = ? ∨ ?
10 / 14
![Page 33: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/33.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Type Semantics: Abstraction?
What about the abstraction function?
Problem: ∧ and ∨ are connectives, not constructors.
α({Int∨Bool,Int∨Int, Int∨Empty})
=
= α({Int, Int, Int}) ∨ α({Bool, Int, Empty})= Int ∨ ?
α({Int ∨ Bool, Bool ∨ Int}) = Int ∨ Bool
10 / 14
![Page 34: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/34.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Outline
1 Motivating Example
2 Types and Subtyping
3 Function Types and Operators
4 Conclusion
10 / 14
![Page 35: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/35.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Typing Applications: Modus Ponens
We start from the usual rule:
Γ ` e1 : σ1 → τ1 Γ ` e2 : σ2 σ2 ≤̃ σ1
Γ ` e1e2 : τ1
Three components:
– Domain– Subtyping check– Result
11 / 14
![Page 36: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/36.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Typing Applications: Modus Ponens
We start from the usual rule:
Γ ` e1 : σ1 → τ1 Γ ` e2 : σ2 σ2 ≤̃ σ1
Γ ` e1e2 : τ1
Three components:– Domain
– Subtyping check– Result
11 / 14
![Page 37: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/37.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Typing Applications: Modus Ponens
We start from the usual rule:
Γ ` e1 : σ1 → τ1 Γ ` e2 : σ2 σ2 ≤̃ σ1
Γ ` e1e2 : τ1
Three components:– Domain– Subtyping check
– Result
11 / 14
![Page 38: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/38.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Typing Applications: Modus Ponens
We start from the usual rule:
Γ ` e1 : σ1 → τ1 Γ ` e2 : σ2 σ2 ≤̃ σ1
Γ ` e1e2 : τ1
Three components:– Domain– Subtyping check– Result
11 / 14
![Page 39: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/39.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Typing Applications: Modus Ponens Revisited
Problem: what is the domain of((Int→ Bool) ∧ ¬Int) ∨ (¬(Bool→ Int) ∧ (Int→ Int))?
Int
What is the result of((Int→ Bool) ∧ (Bool→ Int)) ∨ (Nat→ Nat) applied to Nat?
Nat ∨ Bool
Γ ` e1 : σ Γ ` e2 : τ τ ≤̃ d̃om(σ)
Γ ` e1e2 : σ ◦̃ τ
12 / 14
![Page 40: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/40.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Typing Applications: Modus Ponens Revisited
Problem: what is the domain of((Int→ Bool) ∧ ¬Int) ∨ (¬(Bool→ Int) ∧ (Int→ Int))?
Int
What is the result of((Int→ Bool) ∧ (Bool→ Int)) ∨ (Nat→ Nat) applied to Nat?
Nat ∨ Bool
Γ ` e1 : σ Γ ` e2 : τ τ ≤̃ d̃om(σ)
Γ ` e1e2 : σ ◦̃ τ
12 / 14
![Page 41: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/41.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Typing Applications: Modus Ponens Revisited
Problem: what is the domain of((Int→ Bool) ∧ ¬Int) ∨ (¬(Bool→ Int) ∧ (Int→ Int))?
Int
What is the result of((Int→ Bool) ∧ (Bool→ Int)) ∨ (Nat→ Nat) applied to Nat?
Nat ∨ Bool
Γ ` e1 : σ Γ ` e2 : τ τ ≤̃ d̃om(σ)
Γ ` e1e2 : σ ◦̃ τ
12 / 14
![Page 42: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/42.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Typing Applications: Modus Ponens Revisited
Problem: what is the domain of((Int→ Bool) ∧ ¬Int) ∨ (¬(Bool→ Int) ∧ (Int→ Int))?
Int
What is the result of((Int→ Bool) ∧ (Bool→ Int)) ∨ (Nat→ Nat) applied to Nat?
Nat ∨ Bool
Γ ` e1 : σ Γ ` e2 : τ τ ≤̃ d̃om(σ)
Γ ` e1e2 : σ ◦̃ τ
12 / 14
![Page 43: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/43.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Function Operators: Examples
d̃om((Int→ Int) ∧ (?→?)) =
Any since it can accept any value
d̃om((Int→ Int) ∨ (?→?)) =
Int
((?→ Int) ∧ (?→ Bool))◦̃Int =
Int ∨ Bool
13 / 14
![Page 44: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/44.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Function Operators: Examples
d̃om((Int→ Int) ∧ (?→?)) = Any since it can accept any value
d̃om((Int→ Int) ∨ (?→?)) =
Int
((?→ Int) ∧ (?→ Bool))◦̃Int =
Int ∨ Bool
13 / 14
![Page 45: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/45.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Function Operators: Examples
d̃om((Int→ Int) ∧ (?→?)) = Any since it can accept any value
d̃om((Int→ Int) ∨ (?→?)) =
Int
((?→ Int) ∧ (?→ Bool))◦̃Int =
Int ∨ Bool
13 / 14
![Page 46: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/46.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Function Operators: Examples
d̃om((Int→ Int) ∧ (?→?)) = Any since it can accept any value
d̃om((Int→ Int) ∨ (?→?)) = Int
((?→ Int) ∧ (?→ Bool))◦̃Int =
Int ∨ Bool
13 / 14
![Page 47: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/47.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Function Operators: Examples
d̃om((Int→ Int) ∧ (?→?)) = Any since it can accept any value
d̃om((Int→ Int) ∨ (?→?)) = Int
((?→ Int) ∧ (?→ Bool))◦̃Int =
Int ∨ Bool
13 / 14
![Page 48: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/48.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Function Operators: Examples
d̃om((Int→ Int) ∧ (?→?)) = Any since it can accept any value
d̃om((Int→ Int) ∨ (?→?)) = Int
((?→ Int) ∧ (?→ Bool))◦̃Int = Int ∨ Bool
13 / 14
![Page 49: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/49.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Outline
1 Motivating Example
2 Types and Subtyping
3 Function Types and Operators
4 Conclusion
13 / 14
![Page 50: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/50.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Conclusion and Future Work
Current results:+ Efficient characterization of consistent subtyping+ Sound system+ Supports polymorphism (W.I.P.)– No blame theorem, and no gradual guarantee yet
Future work:– Provide a statically-typed cast-calculus and prove the gradual
guarantee– Study blame
14 / 14
![Page 51: Gradual Typing with Union and Intersection Types · Gradual Typing with Union and Intersection Types GiuseppeCastagna,Victor Lanvin ICFP ’17 September6,2017 1/14. Motivating ExampleTypes](https://reader030.vdocuments.mx/reader030/viewer/2022040911/5e85014ab5a27c58c8045d31/html5/thumbnails/51.jpg)
Motivating Example Types and Subtyping Function Types and Operators Conclusion
Conclusion and Future Work
Current results:+ Efficient characterization of consistent subtyping+ Sound system+ Supports polymorphism (W.I.P.)– No blame theorem, and no gradual guarantee yet
Future work:– Provide a statically-typed cast-calculus and prove the gradual
guarantee– Study blame
14 / 14