Set-theoretic Foundation of Parametric Polymorphism and Subtyping - - PowerPoint PPT Presentation

set theoretic foundation of parametric polymorphism and
SMART_READER_LITE
LIVE PREVIEW

Set-theoretic Foundation of Parametric Polymorphism and Subtyping - - PowerPoint PPT Presentation

ICFP11 Set-theoretic Foundation of Parametric Polymorphism and Subtyping Giuseppe Castagna 1 and Zhiwu Xu 1 , 2 1 CNRS, Laboratoire Preuves, Programmes et Syst` emes, Universit e Paris Diderot, Paris, France. 2 State Key Laboratory of


slide-1
SLIDE 1

logoP7 ICFP’11

Set-theoretic Foundation of Parametric Polymorphism and Subtyping

Giuseppe Castagna1 and Zhiwu Xu1,2

1CNRS, Laboratoire Preuves, Programmes et Syst`

emes, Universit´ e Paris Diderot, Paris, France.

2State Key Laboratory of Computer Science, Institute of Software,

Chinese Academy of Science, Beijing, China

ICFP, Tokyo, 19th of September, 2011

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 1/27

slide-2
SLIDE 2

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Goal

1 Take your favorite type constructors

× × ×, → → →, {. . . }, chan(), . . .

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 2/27

slide-3
SLIDE 3

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Goal

1 Take your favorite type constructors

× × ×, → → →, {. . . }, chan(), . . .

2 add Boolean connectives:

∨ ∨ ∨, ∧ ∧ ∧, ¬ ¬ ¬

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 2/27

slide-4
SLIDE 4

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Goal

1 Take your favorite type constructors

× × ×, → → →, {. . . }, chan(), . . .

2 add Boolean connectives:

∨ ∨ ∨, ∧ ∧ ∧, ¬ ¬ ¬

3 add type variables

α, β, γ, ...

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 2/27

slide-5
SLIDE 5

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Goal

1 Take your favorite type constructors

× × ×, → → →, {. . . }, chan(), . . .

2 add Boolean connectives:

∨ ∨ ∨, ∧ ∧ ∧, ¬ ¬ ¬

3 add type variables

α, β, γ, ...

4 give an intuitive (ie, set-theoretic) semantics so as to deduce

classic distribution laws (for all α, β, γ) ((α∨ ∨ ∨β)× × ×γ) ⋚ (α× × ×γ) ∨ (β× × ×γ)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 2/27

slide-6
SLIDE 6

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Goal

1 Take your favorite type constructors

× × ×, → → →, {. . . }, chan(), . . .

2 add Boolean connectives:

∨ ∨ ∨, ∧ ∧ ∧, ¬ ¬ ¬

3 add type variables

α, β, γ, ...

4 give an intuitive (ie, set-theoretic) semantics so as to deduce

classic distribution laws (for all α, β, γ) ((α∨ ∨ ∨β)× × ×γ) ⋚ (α× × ×γ) ∨ (β× × ×γ) data structure containments (for all α): µt.(α× × ×(α× × ×t))∨ ∨ ∨nil

  • α-lists of even length

≤ µt.(α× × ×t)∨ ∨ ∨nil

  • α-lists

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 2/27

slide-7
SLIDE 7

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Goal

1 Take your favorite type constructors

× × ×, → → →, {. . . }, chan(), . . .

2 add Boolean connectives:

∨ ∨ ∨, ∧ ∧ ∧, ¬ ¬ ¬

3 add type variables

α, β, γ, ...

4 give an intuitive (ie, set-theoretic) semantics so as to deduce

classic distribution laws (for all α, β, γ) ((α∨ ∨ ∨β)× × ×γ) ⋚ (α× × ×γ) ∨ (β× × ×γ) data structure containments (for all α): µt.(α× × ×(α× × ×t))∨ ∨ ∨nil

  • α-lists of even length

≤ µt.(α× × ×t)∨ ∨ ∨nil

  • α-lists

WHY?

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 2/27

slide-8
SLIDE 8

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

WHY? briefly:

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 3/27

slide-9
SLIDE 9

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

WHY? briefly:

1 Boolean connectives:

Unions, products and recursive types encode regular trees and therefore XML Intersection and negation permit XML typed programming with overloading and powerful pattern matching.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 3/27

slide-10
SLIDE 10

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

WHY? briefly:

1 Boolean connectives:

Unions, products and recursive types encode regular trees and therefore XML Intersection and negation permit XML typed programming with overloading and powerful pattern matching.

2 Type variables:

Parametric polymorphism already demonstrated its worth in practice. Fulfills new needs specific to XML processing (eg, SOAP envelopes). Sheds new light on the notion of parametricity.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 3/27

slide-11
SLIDE 11

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-12
SLIDE 12

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

1 define a function from the query string to Xhtml:

let page_fun(p: {title: string, ...}) : Xhtml = ...

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-13
SLIDE 13

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

1 define a function from the query string to Xhtml:

let page_fun(p: {title: string, ...}) : Xhtml = ...

2 bind page fun to the path $WEBROOT/w/index by:

register new service register new service register new service(page fun,"w/index")

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-14
SLIDE 14

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

1 define a function from the query string to Xhtml:

let page_fun(p: {title: string, ...}) : Xhtml = ...

2 bind page fun to the path $WEBROOT/w/index by:

register new service register new service register new service(page fun,"w/index") The (wished) type of register_new_service is ∀(X ≤ Params).((X → → → Xhtml) × Path) → unit where Params is a specification of all possible query strings

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-15
SLIDE 15

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

1 define a function from the query string to Xhtml:

let page_fun(p: {title: string, ...}) : Xhtml = ...

2 bind page fun to the path $WEBROOT/w/index by:

register new service register new service register new service(page fun,"w/index") The (wished) type of register_new_service is ∀(X ≤ Params).((X → → → Xhtml) × Path) → unit where Params is a specification of all possible query strings

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-16
SLIDE 16

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

1 define a function from the query string to Xhtml:

let page_fun(p: {title: string, ...}) : Xhtml = ...

2 bind page fun to the path $WEBROOT/w/index by:

register new service register new service register new service(page fun,"w/index") The (wished) type of register_new_service is ∀(X ≤ Params).((X → → → Xhtml) × Path) → unit where Params is a specification of all possible query strings

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-17
SLIDE 17

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

1 define a function from the query string to Xhtml:

let page_fun(p: {title: string, ...}) : Xhtml = ...

2 bind page fun to the path $WEBROOT/w/index by:

register new service register new service register new service(page fun,"w/index") The (wished) type of register_new_service is ∀(X ≤ Params).((X → → → Xhtml) × Path) → unit where Params is a specification of all possible query strings

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-18
SLIDE 18

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

1 define a function from the query string to Xhtml:

let page_fun(p: {title: string, ...}) : Xhtml = ...

2 bind page fun to the path $WEBROOT/w/index by:

register new service register new service register new service(page fun,"w/index") The (wished) type of register_new_service is ∀(X ≤ Params).((X → → → Xhtml) × Path) → unit where Params is a specification of all possible query strings

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-19
SLIDE 19

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Real case example: active pages

To create a dynamically generated page in the Ocsigen web development systems:

1 define a function from the query string to Xhtml:

let page_fun(p: {title: string, ...}) : Xhtml = ...

2 bind page fun to the path $WEBROOT/w/index by:

register new service register new service register new service(page fun,"w/index") The (wished) type of register_new_service is ∀(X ≤ Params).((X → → → Xhtml) × Path) → unit where Params is a specification of all possible query strings

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 4/27

slide-20
SLIDE 20

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Current status

Study of a type system of (recursive/regular) types with t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α type constructors logical connectives type variables ❈

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 5/27

slide-21
SLIDE 21

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Current status

Study of a type system of (recursive/regular) types with t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α type constructors logical connectives type variables Logical connectives: Well-known how to implement a functional language with pattern-matching, higher-order functions, and connectives with set theoretic interpretation. ❈

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 5/27

slide-22
SLIDE 22

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Current status

Study of a type system of (recursive/regular) types with t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α type constructors logical connectives type variables Logical connectives: Well-known how to implement a functional language with pattern-matching, higher-order functions, and connectives with set theoretic interpretation. Semantic subtyping (implemented by the language ❈Duce).

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 5/27

slide-23
SLIDE 23

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Current status

Study of a type system of (recursive/regular) types with t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α type constructors logical connectives type variables Logical connectives: Well-known how to implement a functional language with pattern-matching, higher-order functions, and connectives with set theoretic interpretation. Semantic subtyping (implemented by the language ❈Duce). Type variables: A set-theoretic approach was deemed unfeasible or even impossible:

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 5/27

slide-24
SLIDE 24

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Current status

Study of a type system of (recursive/regular) types with t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α type constructors logical connectives type variables Logical connectives: Well-known how to implement a functional language with pattern-matching, higher-order functions, and connectives with set theoretic interpretation. Semantic subtyping (implemented by the language ❈Duce). Type variables: A set-theoretic approach was deemed unfeasible or even impossible: This work (built on the work of semantic subtyping)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 5/27

slide-25
SLIDE 25

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic Subtyping in a nutshell

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 6/27

slide-26
SLIDE 26

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 7/27

slide-27
SLIDE 27

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ Constructor subtyping is easy: constructors do not mix, eg.: s2 ≤ s1 t1 ≤ t2 s1→ → →t1 ≤ s2→ → →t2

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 7/27

slide-28
SLIDE 28

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ Constructor subtyping is easy: constructors do not mix, eg.: s2 ≤ s1 t1 ≤ t2 s1→ → →t1 ≤ s2→ → →t2 Connective subtyping is harder: connectives distribute over constructors, eg. (s1∨ ∨ ∨s2)→ → →t

  • (s1→

→ →t)∧ ∧ ∧(s2→ → →t)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 7/27

slide-29
SLIDE 29

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ Constructor subtyping is easy: constructors do not mix, eg.: s2 ≤ s1 t1 ≤ t2 s1→ → →t1 ≤ s2→ → →t2 Connective subtyping is harder: connectives distribute over constructors, eg. (s1∨ ∨ ∨s2)→ → →t

  • (s1→

→ →t)∧ ∧ ∧(s2→ → →t) Define subtyping semantically:

[Hosoya, Pierce]

1 Interpret types as sets (of values) 2 Define subtyping as set containment. Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 7/27

slide-30
SLIDE 30

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that ✵

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-31
SLIDE 31

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-32
SLIDE 32

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = {f | f function fromt1 to t2} DD ⊆ D

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-33
SLIDE 33

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = {f | f function fromt1 to t2} DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-34
SLIDE 34

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = {f | f function fromt1 to t2} DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-35
SLIDE 35

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = {f | f function fromt1 to t2} DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-36
SLIDE 36

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = {f | f function fromt1 to t2} DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t Key idea Do not define what types are define how they are related

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-37
SLIDE 37

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = {f | f function fromt1 to t2} DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t Key idea Do not define what types are define how they are related

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-38
SLIDE 38

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ t1→ → →t2 = {f ⊆ D2 | (d1, d2)∈f , d1∈t1 ⇒ d2∈t2} DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t Key idea Do not define what types are define how they are related

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-39
SLIDE 39

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = P(t1 × t2) DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t Key idea Do not define what types are define how they are related

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-40
SLIDE 40

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = P(t1 × t2) DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t Key idea Do not define what types are define how they are related

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-41
SLIDE 41

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have the same ⊆ as their natural interpretation: t1× × ×t2 = t1× × ×t2 D2 ⊆ D t1→ → →t2 = P(t1 × t2) DD ⊆ D Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t Key idea Do not define what types are define how they are related

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-42
SLIDE 42

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have the same ⊆ as their natural interpretation: s1× × ×s2 ⊆ t1× × ×t2 ⇐ ⇒ s1× × ×s2 ⊆ t1× × ×t2 s1→ → →s2 ⊆ t1→ → →t2 ⇐ ⇒ P(s1 × s2) ⊆ P(t1 × t2) Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t Key idea Do not define what types are define how they are related

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-43
SLIDE 43

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Semantic subtyping: formalization

First, define an interpretation of types into sets. : Types → P(D) such that Connectives have their set-theoretic interpretation: ✵ = ∅ t1∨ ∨ ∨t2 = t1∪ ∪ ∪t2 ¬ ¬ ¬t = D\ \ \t t1∧ ∧ ∧t2 = t1∩ ∩ ∩t2 Constructors have the same ⊆ as their natural interpretation: s1× × ×s2 ⊆ t1× × ×t2 ⇐ ⇒ s1× × ×s2 ⊆ t1× × ×t2 s1→ → →s2 ⊆ t1→ → →t2 ⇐ ⇒ P(s1 × s2) ⊆ P(t1 × t2) Then define the subtyping relation as set-containment. s ≤ t

def

⇐ ⇒ s ⊆ t Semantic subtyping

[Benzaken, Castagna, Frisch]

1 Gives an interpretation satisfying the above constraints; 2 Gives an algorithm to decide the induced subtyping relation. Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 8/27

slide-44
SLIDE 44

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Polymorphic extension: adding type variables

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 9/27

slide-45
SLIDE 45

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Naive solution

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 10/27

slide-46
SLIDE 46

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Naive solution

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 10/27

slide-47
SLIDE 47

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Naive solution

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α Idea: Use the previous relation since is defined for “ground types” Let σ : Vars → ClosedTypes denote ground substitutions. Define:

s ≤ t

def

⇐ ⇒ ∀σ . sσ ≤ tσ

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 10/27

slide-48
SLIDE 48

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Naive solution

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α Idea: Use the previous relation since is defined for “ground types” Let σ : Vars → ClosedTypes denote ground substitutions. Define:

s ≤ t

def

⇐ ⇒ ∀σ . sσ ≤ tσ

  • r equivalently

s ≤ t

def

⇐ ⇒ ∀σ.sσ ⊆ tσ

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 10/27

slide-49
SLIDE 49

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Naive solution

t ::= B | t× × ×t | t→ → →t | t∨ ∨ ∨t | t∧ ∧ ∧t | ¬t | ✵ | ✶ | α α α Idea: Use the previous relation since is defined for “ground types” Let σ : Vars → ClosedTypes denote ground substitutions. Define:

s ≤ t

def

⇐ ⇒ ∀σ . sσ ≤ tσ

  • r equivalently

s ≤ t

def

⇐ ⇒ ∀σ.sσ ⊆ tσ

THIS IS A WRONG WAY: TOO MANY PROBLEMS

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 10/27

slide-50
SLIDE 50

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

1 Haruo Hosoya conjectured that deciding ∀σ . sσ ≤ tσ is at

least as hard as solving Diophantine equations

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 11/27

slide-51
SLIDE 51

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

1 Haruo Hosoya conjectured that deciding ∀σ . sσ ≤ tσ is at

least as hard as solving Diophantine equations

2 It breaks parametricity: Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 11/27

slide-52
SLIDE 52

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

1 Haruo Hosoya conjectured that deciding ∀σ . sσ ≤ tσ is at

least as hard as solving Diophantine equations

2 It breaks parametricity:

(t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) (1)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 11/27

slide-53
SLIDE 53

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

1 Haruo Hosoya conjectured that deciding ∀σ . sσ ≤ tσ is at

least as hard as solving Diophantine equations

2 It breaks parametricity:

(t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) (1) This inclusion holds if and only if t is an indivisible type (eg., a singleton or a basic type):

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 11/27

slide-54
SLIDE 54

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

1 Haruo Hosoya conjectured that deciding ∀σ . sσ ≤ tσ is at

least as hard as solving Diophantine equations

2 It breaks parametricity:

(t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) (1) This inclusion holds if and only if t is an indivisible type (eg., a singleton or a basic type): Property of indivisible types If t is an indivisible type, then for all possible interpretations of α α α t ≤ α α α

  • r

α α α ≤ ¬ ¬ ¬t holds.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 11/27

slide-55
SLIDE 55

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

1 Haruo Hosoya conjectured that deciding ∀σ . sσ ≤ tσ is at

least as hard as solving Diophantine equations

2 It breaks parametricity:

(t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) (1) This inclusion holds if and only if t is an indivisible type (eg., a singleton or a basic type): Property of indivisible types If t is an indivisible type, then for all possible interpretations of α α α t ≤ α α α

  • r

α α α ≤ ¬ ¬ ¬t holds.

If α α α ≤ ¬ ¬ ¬t then the left element of the union in (18) suffices; If t ≤ α α α, then α α α = (α α α\t)∨ ∨ ∨t. Thus (t× × ×α α α) = (t× × ×(α α α\t))∨ ∨ ∨(t× × ×t). This union is contained component-wise in the one in (18).

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 11/27

slide-56
SLIDE 56

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

The fact that (t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) holds if and only if t is indivisible is really catastrophic:

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 12/27

slide-57
SLIDE 57

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

The fact that (t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) holds if and only if t is indivisible is really catastrophic: Deciding subtyping needs deciding indivisibility ... which is very hard.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 12/27

slide-58
SLIDE 58

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

The fact that (t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) holds if and only if t is indivisible is really catastrophic: Deciding subtyping needs deciding indivisibility ... which is very hard. This subtyping relation breaks parametricity: by subsumption a function generic in its first argument, becomes generic on its second argument.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 12/27

slide-59
SLIDE 59

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

The fact that (t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) holds if and only if t is indivisible is really catastrophic: Deciding subtyping needs deciding indivisibility ... which is very hard. This subtyping relation breaks parametricity: by subsumption a function generic in its first argument, becomes generic on its second argument. A semantic solution was deemed unfeasible (even w/o arrows) Problem eschewed by resorting to syntactic solutions: [Hosoya, Frisch, Castagna: POPL 05], [Vouillon: POPL 06].

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 12/27

slide-60
SLIDE 60

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Problems with the naive solution

The fact that (t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t) holds if and only if t is indivisible is really catastrophic: Deciding subtyping needs deciding indivisibility ... which is very hard. This subtyping relation breaks parametricity: by subsumption a function generic in its first argument, becomes generic on its second argument. A semantic solution was deemed unfeasible (even w/o arrows) Problem eschewed by resorting to syntactic solutions: [Hosoya, Frisch, Castagna: POPL 05], [Vouillon: POPL 06].

A SEMANTIC SOLUTION IS POSSIBLE

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 12/27

slide-61
SLIDE 61

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

A semantic solution

A faint intuition The loss of parametricity is only due to the interpretation of indivisible types, all the rest works (more or less) smoothly

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 13/27

slide-62
SLIDE 62

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

A semantic solution

A faint intuition The loss of parametricity is only due to the interpretation of indivisible types, all the rest works (more or less) smoothly The crux of the problem is that for an indivisible type i i i i i i ≤ α α α

  • r

α α α ≤ ¬ ¬ ¬i i i validity can stutter from one formula to another, missing in this way the uniformity typical of parametricity

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 13/27

slide-63
SLIDE 63

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

A semantic solution

A faint intuition The loss of parametricity is only due to the interpretation of indivisible types, all the rest works (more or less) smoothly The crux of the problem is that for an indivisible type i i i i i i ≤ α α α

  • r

α α α ≤ ¬ ¬ ¬i i i validity can stutter from one formula to another, missing in this way the uniformity typical of parametricity The leitmotif of this work A semantic characterization of models where stuttering is absent, should yield a subtyping relation that is:

1 Semantic 2 Intuitive for the programmer 3 Decidable Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 13/27

slide-64
SLIDE 64

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

A semantic solution

Rough idea Make indivisible types “splittable” so that type variables can range over strict subsets of every type, indivisible types included.

[intuition: interpret all non-empty types into infinite sets]

✵ ✶

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 14/27

slide-65
SLIDE 65

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

A semantic solution

Rough idea Make indivisible types “splittable” so that type variables can range over strict subsets of every type, indivisible types included.

[intuition: interpret all non-empty types into infinite sets]

Since this cannot be done at syntactic level, move to the semantic

  • ne and replace ground substitutions by semantic assignments:

η : Vars → P(D) ✵ ✶

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 14/27

slide-66
SLIDE 66

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

A semantic solution

Rough idea Make indivisible types “splittable” so that type variables can range over strict subsets of every type, indivisible types included.

[intuition: interpret all non-empty types into infinite sets]

Since this cannot be done at syntactic level, move to the semantic

  • ne and replace ground substitutions by semantic assignments:

η : Vars → P(D) and now the interpretation function takes an extra parameter : Types → P(D)Vars → P(D) ✵ ✶

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 14/27

slide-67
SLIDE 67

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

A semantic solution

Rough idea Make indivisible types “splittable” so that type variables can range over strict subsets of every type, indivisible types included.

[intuition: interpret all non-empty types into infinite sets]

Since this cannot be done at syntactic level, move to the semantic

  • ne and replace ground substitutions by semantic assignments:

η : Vars → P(D) and now the interpretation function takes an extra parameter : Types → P(D)Vars → P(D) with α α αη = η(α α α) ¬ ¬ ¬tη = D\tη t1∨ ∨ ∨t2η = t1η ∪ t2η t1∧ ∧ ∧t2η = t1η ∩ t2η ✵η = ∅ ✶η = D

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 14/27

slide-68
SLIDE 68

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

A semantic solution

Rough idea Make indivisible types “splittable” so that type variables can range over strict subsets of every type, indivisible types included.

[intuition: interpret all non-empty types into infinite sets]

Since this cannot be done at syntactic level, move to the semantic

  • ne and replace ground substitutions by semantic assignments:

η : Vars → P(D) and now the interpretation function takes an extra parameter : Types → P(D)Vars → P(D) with α α αη = η(α α α) ¬ ¬ ¬tη = D\tη t1∨ ∨ ∨t2η = t1η ∪ t2η t1∧ ∧ ∧t2η = t1η ∩ t2η ✵η = ∅ ✶η = D and such that it satisfies: t1→ → →s1η ⊆ t2→ → →s2η ⇐ ⇒ P(t1η × s1η) ⊆ P(t2η × s2η)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 14/27

slide-69
SLIDE 69

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Subtyping relation

In this framework the natural definition of subtyping is s ≤ t

def

⇐ ⇒ ∀η . sη ⊆ tη It “just” remains to find the uniformity condition to avoid stuttering and recover parametricity.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 15/27

slide-70
SLIDE 70

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

The magic property: convexity

Consider only models of semantic subtyping in which the following convexity property holds ∀η.(t1η=∅ or t2η=∅) ⇐ ⇒ (∀η.t1η=∅) or (∀η.t2η=∅)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 16/27

slide-71
SLIDE 71

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

The magic property: convexity

Consider only models of semantic subtyping in which the following convexity property holds ∀η.(t1η=∅ or t2η=∅) ⇐ ⇒ (∀η.t1η=∅) or (∀η.t2η=∅) It avoids stuttering: ∀η.(t∧ ∧ ∧¬ ¬ ¬α α αη=∅ or t∧ ∧ ∧α α αη=∅) —that is, (t ≤ α α α or α α α ≤ ¬ ¬ ¬t)— holds if and only if t is empty.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 16/27

slide-72
SLIDE 72

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

The magic property: convexity

Consider only models of semantic subtyping in which the following convexity property holds ∀η.(t1η=∅ or t2η=∅) ⇐ ⇒ (∀η.t1η=∅) or (∀η.t2η=∅) It avoids stuttering: ∀η.(t∧ ∧ ∧¬ ¬ ¬α α αη=∅ or t∧ ∧ ∧α α αη=∅) —that is, (t ≤ α α α or α α α ≤ ¬ ¬ ¬t)— holds if and only if t is empty. There are natural models: all models that map all non-empty types into infinite sets satisfy it [our initial intuition].

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 16/27

slide-73
SLIDE 73

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

The magic property: convexity

Consider only models of semantic subtyping in which the following convexity property holds ∀η.(t1η=∅ or t2η=∅) ⇐ ⇒ (∀η.t1η=∅) or (∀η.t2η=∅) It avoids stuttering: ∀η.(t∧ ∧ ∧¬ ¬ ¬α α αη=∅ or t∧ ∧ ∧α α αη=∅) —that is, (t ≤ α α α or α α α ≤ ¬ ¬ ¬t)— holds if and only if t is empty. There are natural models: all models that map all non-empty types into infinite sets satisfy it [our initial intuition]. A sound, complete, and terminating decision algorithm: the condition gives us exactly the right conditions needed to reuse the subtyping algorithm devised for ground types.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 16/27

slide-74
SLIDE 74

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

The magic property: convexity

Consider only models of semantic subtyping in which the following convexity property holds ∀η.(t1η=∅ or t2η=∅) ⇐ ⇒ (∀η.t1η=∅) or (∀η.t2η=∅) It avoids stuttering: ∀η.(t∧ ∧ ∧¬ ¬ ¬α α αη=∅ or t∧ ∧ ∧α α αη=∅) —that is, (t ≤ α α α or α α α ≤ ¬ ¬ ¬t)— holds if and only if t is empty. There are natural models: all models that map all non-empty types into infinite sets satisfy it [our initial intuition]. A sound, complete, and terminating decision algorithm: the condition gives us exactly the right conditions needed to reuse the subtyping algorithm devised for ground types. An intuitive relation: the algorithm returns intuitive results (actually, it helps to better understand twisted examples)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 16/27

slide-75
SLIDE 75

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

The magic property: convexity

Consider only models of semantic subtyping in which the following convexity property holds ∀η.(t1η=∅ or t2η=∅) ⇐ ⇒ (∀η.t1η=∅) or (∀η.t2η=∅) It avoids stuttering: ∀η.(t∧ ∧ ∧¬ ¬ ¬α α αη=∅ or t∧ ∧ ∧α α αη=∅) —that is, (t ≤ α α α or α α α ≤ ¬ ¬ ¬t)— holds if and only if t is empty. There are natural models: all models that map all non-empty types into infinite sets satisfy it [our initial intuition]. A sound, complete, and terminating decision algorithm: the condition gives us exactly the right conditions needed to reuse the subtyping algorithm devised for ground types. An intuitive relation: the algorithm returns intuitive results (actually, it helps to better understand twisted examples)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 16/27

slide-76
SLIDE 76

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Examples of subtyping relations

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 17/27

slide-77
SLIDE 77

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Examples

We can internalize properties such as: (α → γ) ∧ (β → γ) ∼ α∨β → γ

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 18/27

slide-78
SLIDE 78

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Examples

We can internalize properties such as: (α → γ) ∧ (β → γ) ∼ α∨β → γ

  • r distributivity laws:

(α∨β × γ) ∼ (α×γ) ∨ (β×γ)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 18/27

slide-79
SLIDE 79

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Examples

We can internalize properties such as: (α → γ) ∧ (β → γ) ∼ α∨β → γ

  • r distributivity laws:

(α∨β × γ) ∼ (α×γ) ∨ (β×γ) and combining them deduce: (α×γ → δ1) ∧ (β×γ → δ2) ≤ (α∨β × γ) → δ1 ∨ δ2

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 18/27

slide-80
SLIDE 80

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Examples

We can internalize properties such as: (α → γ) ∧ (β → γ) ∼ α∨β → γ

  • r distributivity laws:

(α∨β × γ) ∼ (α×γ) ∨ (β×γ) and combining them deduce: (α×γ → δ1) ∧ (β×γ → δ2) ≤ (α∨β × γ) → δ1 ∨ δ2 Of course the problematic relation never holds, whatever the t: (t× × ×α α α) ≤ (t× × ×¬ ¬ ¬t)∨ ∨ ∨(α α α× × ×t)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 18/27

slide-81
SLIDE 81

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

We can prove relevant relations on infinite types, eg., for the type

  • f generic α

α α-lists: α α α-list = µz.(α α α× × ×z)∨ ∨ ∨ nil

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 19/27

slide-82
SLIDE 82

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

We can prove relevant relations on infinite types, eg., for the type

  • f generic α

α α-lists: α α α-list = µz.(α α α× × ×z)∨ ∨ ∨ nil we can prove that it contains both the α-lists of even length µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ nil

  • α-lists of even length

≤ ≤ ≤ µz.(α α α× × ×z)∨ ∨ ∨ nil

  • α-lists

and the α-lists with of odd length µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ (α α α× × ×nil)

  • α-lists of odd length

≤ ≤ ≤ µz.(α α α× × ×z)∨ ∨ ∨ nil

  • α-lists

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 19/27

slide-83
SLIDE 83

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

We can prove relevant relations on infinite types, eg., for the type

  • f generic α

α α-lists: α α α-list = µz.(α α α× × ×z)∨ ∨ ∨ nil we can prove that it contains both the α-lists of even length µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ nil

  • α-lists of even length

≤ ≤ ≤ µz.(α α α× × ×z)∨ ∨ ∨ nil

  • α-lists

and the α-lists with of odd length µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ (α α α× × ×nil)

  • α-lists of odd length

≤ ≤ ≤ µz.(α α α× × ×z)∨ ∨ ∨ nil

  • α-lists

and that it is itself contained in the union of the two, that is: α α α-list ∼ ∼ ∼ (µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ nil) ∨ ∨ ∨ (µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ (α α α× × ×nil))

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 19/27

slide-84
SLIDE 84

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

We can prove relevant relations on infinite types, eg., for the type

  • f generic α

α α-lists: α α α-list = µz.(α α α× × ×z)∨ ∨ ∨ nil we can prove that it contains both the α-lists of even length µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ nil

  • α-lists of even length

≤ ≤ ≤ µz.(α α α× × ×z)∨ ∨ ∨ nil

  • α-lists

and the α-lists with of odd length µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ (α α α× × ×nil)

  • α-lists of odd length

≤ ≤ ≤ µz.(α α α× × ×z)∨ ∨ ∨ nil

  • α-lists

and that it is itself contained in the union of the two, that is: α α α-list ∼ ∼ ∼ (µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ nil) ∨ ∨ ∨ (µz.(α α α× × ×(α α α× × ×z))∨ ∨ ∨ (α α α× × ×nil)) And we can prove far more complicated relations (see paper).

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 19/27

slide-85
SLIDE 85

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Subtyping algorithm

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 20/27

slide-86
SLIDE 86

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Subtyping Algorithm: t1 ≤ t2

Step 1: Transform the subtyping problem into an emptiness decision problem: t1 ≤ t2 ⇐ ⇒ ∀η.t1η ⊆ t2η ⇐ ⇒ ∀η.t1∧¬t2η=∅ ⇐ ⇒ t1∧¬t2 ≤ ✵ ✵ ✶

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 21/27

slide-87
SLIDE 87

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Subtyping Algorithm: t1 ≤ t2

Step 1: Transform the subtyping problem into an emptiness decision problem: t1 ≤ t2 ⇐ ⇒ ∀η.t1η ⊆ t2η ⇐ ⇒ ∀η.t1∧¬t2η=∅ ⇐ ⇒ t1∧¬t2 ≤ ✵ Step 2: Put the type whose emptiness is to be decided in disjunctive normal form.

  • i∈I
  • j∈J

ℓij where a ::= b | t × t | t → t | ✵ | ✶ | α and ℓ ::= a | ¬a

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 21/27

slide-88
SLIDE 88

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Subtyping Algorithm: t1 ≤ t2

Step 1: Transform the subtyping problem into an emptiness decision problem: t1 ≤ t2 ⇐ ⇒ ∀η.t1η ⊆ t2η ⇐ ⇒ ∀η.t1∧¬t2η=∅ ⇐ ⇒ t1∧¬t2 ≤ ✵ Step 2: Put the type whose emptiness is to be decided in disjunctive normal form.

  • i∈I
  • j∈J

ℓij where a ::= b | t × t | t → t | ✵ | ✶ | α and ℓ ::= a | ¬a Step 3: Simplify mixed intersections: Consider each summand of the union: cases such as t1×t2 ∧ t1→t2 or t1×t2 ∧ ¬(t1→t2) are straightforward. Solve:

  • i∈I

ai

  • j∈J

¬a′

j

  • h∈H

αh

  • k∈K

¬βk where all a are of the same kind.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 21/27

slide-89
SLIDE 89

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Step 4: Eliminate toplevel negative variables., ∀η.tη = ∅ ⇐ ⇒ ∀η.t{¬α /

α}η = ∅

so replace ¬βk for βk (forall k ∈ K) Solve:

  • i∈I

ai

  • j∈J

¬a′

j

  • h∈H

αh

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 22/27

slide-90
SLIDE 90

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Step 4: Eliminate toplevel negative variables., ∀η.tη = ∅ ⇐ ⇒ ∀η.t{¬α /

α}η = ∅

so replace ¬βk for βk (forall k ∈ K) Solve:

  • i∈I

ai

  • j∈J

¬a′

j

  • h∈H

αh Step 5: Eliminate toplevel variables.

  • t1×t2∈P

t1×t2

  • h∈H

αh ≤

  • t′

1×t′ 2∈N

t′

1×t′ 2

holds if and only if

  • t1×t2∈P

t1σ × t2σ

  • h∈H

γ1

h × γ2 h

  • t′

1×t′ 2∈N

t′

1σ × t′ 2σ

where σ = {(γ1

h×γ2 h) ∨ αh/αh}h∈H

(similarly for arrows)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 22/27

slide-91
SLIDE 91

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Step 6: Eliminate toplevel constructors, memoize, and recurse. Thanks to convexity and (set-theoretic) product decomposition rules

  • t1×t2∈P

t1×t2 ≤

  • t′

1×t′ 2∈N

t′

1×t′ 2

(2) is equivalent to ∀N′⊆N.  

  • t1×t2∈P

t1 ≤

  • t′

1×t′ 2∈N′

t′

1

  or  

  • t1×t2∈P

t2 ≤

  • t′

1×t′ 2∈N\N′

t′

2

  (similarly for arrows)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 23/27

slide-92
SLIDE 92

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Conclusion and New Directions

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 24/27

slide-93
SLIDE 93

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Conclusion

We presented the first known solution to the problem of defining a semantic subtyping relation for a polymorphic regular tree types. A solution to this problem was considered unfeasible

  • r even impossible.

Our solution immediately applies to functional XML processing, but the potential fields of application seem much more numerous. Finally, our work opens both practical and theoretical new directions of research.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 25/27

slide-94
SLIDE 94

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Practical problems

New typing possibilities: fun even even even = | Int -> (x mod 2) == 0 | _

  • > x

Intuitively we want to type it by (Int→ → →Bool) ∧ ∧ ∧ (α α α\ \ \Int → α α α\ \ \Int)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 26/27

slide-95
SLIDE 95

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Practical problems

New typing possibilities: fun even even even = | Int -> (x mod 2) == 0 | _

  • > x

Intuitively we want to type it by (Int→ → →Bool) ∧ ∧ ∧ (α α α\ \ \Int → α α α\ \ \Int) Local type inference: Let map map map : (α → β) → α list → β list, then for map even map even map even we wish to deduce the following type: ( Int list → Bool list ) ∧ ∧ ∧

int lists return bool lists

( (α α α\ \ \Int) list → (α α α\ \ \Int) list ) ∧ ∧ ∧

lists w/o ints return the same type

(α α α list → ((α α α\ \ \Int)∨ ∨ ∨Bool) list )

ints in the argument are replaced by bools

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 26/27

slide-96
SLIDE 96

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Practical problems

New typing possibilities: fun even even even = | Int -> (x mod 2) == 0 | _

  • > x

Intuitively we want to type it by (Int→ → →Bool) ∧ ∧ ∧ (α α α\ \ \Int → α α α\ \ \Int) Local type inference: Let map map map : (α → β) → α list → β list, then for map even map even map even we wish to deduce the following type: ( Int list → Bool list ) ∧ ∧ ∧

int lists return bool lists

( (α α α\ \ \Int) list → (α α α\ \ \Int) list ) ∧ ∧ ∧

lists w/o ints return the same type

(α α α list → ((α α α\ \ \Int)∨ ∨ ∨Bool) list )

ints in the argument are replaced by bools

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 26/27

slide-97
SLIDE 97

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Practical problems

New typing possibilities: fun even even even = | Int -> (x mod 2) == 0 | _

  • > x

Intuitively we want to type it by (Int→ → →Bool) ∧ ∧ ∧ (α α α\ \ \Int → α α α\ \ \Int) Local type inference: Let map map map : (α → β) → α list → β list, then for map even map even map even we wish to deduce the following type: ( Int list → Bool list ) ∧ ∧ ∧

int lists return bool lists

( (α α α\ \ \Int) list → (α α α\ \ \Int) list ) ∧ ∧ ∧

lists w/o ints return the same type

(α α α list → ((α α α\ \ \Int)∨ ∨ ∨Bool) list )

ints in the argument are replaced by bools

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 26/27

slide-98
SLIDE 98

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Practical problems

New typing possibilities: fun even even even = | Int -> (x mod 2) == 0 | _

  • > x

Intuitively we want to type it by (Int→ → →Bool) ∧ ∧ ∧ (α α α\ \ \Int → α α α\ \ \Int) Local type inference: Let map map map : (α → β) → α list → β list, then for map even map even map even we wish to deduce the following type: ( Int list → Bool list ) ∧ ∧ ∧

int lists return bool lists

( (α α α\ \ \Int) list → (α α α\ \ \Int) list ) ∧ ∧ ∧

lists w/o ints return the same type

(α α α list → ((α α α\ \ \Int)∨ ∨ ∨Bool) list )

ints in the argument are replaced by bools

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 26/27

slide-99
SLIDE 99

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Practical problems

New typing possibilities: fun even even even = | Int -> (x mod 2) == 0 | _

  • > x

Intuitively we want to type it by (Int→ → →Bool) ∧ ∧ ∧ (α α α\ \ \Int → α α α\ \ \Int) Local type inference: Let map map map : (α → β) → α list → β list, then for map even map even map even we wish to deduce the following type: ( Int list → Bool list ) ∧ ∧ ∧

int lists return bool lists

( (α α α\ \ \Int) list → (α α α\ \ \Int) list ) ∧ ∧ ∧

lists w/o ints return the same type

(α α α list → ((α α α\ \ \Int)∨ ∨ ∨Bool) list )

ints in the argument are replaced by bools

Cannot be obtained by just instantiating the type of map

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 26/27

slide-100
SLIDE 100

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Practical problems

New typing possibilities: fun even even even = | Int -> (x mod 2) == 0 | _

  • > x

Intuitively we want to type it by (Int→ → →Bool) ∧ ∧ ∧ (α α α\ \ \Int → α α α\ \ \Int) Local type inference: Let map map map : (α → β) → α list → β list, then for map even map even map even we wish to deduce the following type: ( Int list → Bool list ) ∧ ∧ ∧

int lists return bool lists

( (α α α\ \ \Int) list → (α α α\ \ \Int) list ) ∧ ∧ ∧

lists w/o ints return the same type

(α α α list → ((α α α\ \ \Int)∨ ∨ ∨Bool) list )

ints in the argument are replaced by bools

Cannot be obtained by just instantiating the type of map No principal typing (needs infinite connectives)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 26/27

slide-101
SLIDE 101

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Practical problems

New typing possibilities: new language design fun even even even = | Int -> (x mod 2) == 0 | _

  • > x

Intuitively we want to type it by (Int→ → →Bool) ∧ ∧ ∧ (α α α\ \ \Int → α α α\ \ \Int) Local type inference: subtyping + instantiation Let map map map : (α → β) → α list → β list, then for map even map even map even we wish to deduce the following type: ( Int list → Bool list ) ∧ ∧ ∧

int lists return bool lists

( (α α α\ \ \Int) list → (α α α\ \ \Int) list ) ∧ ∧ ∧

lists w/o ints return the same type

(α α α list → ((α α α\ \ \Int)∨ ∨ ∨Bool) list )

ints in the argument are replaced by bools

Cannot be obtained by just instantiating the type of map No principal typing (needs infinite connectives)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 26/27

slide-102
SLIDE 102

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Convexity and parametricity?

In reality, the condition to be used is the generalization to n types: ∀η.(t1η=∅ or · · · or tnη=∅) ⇐ ⇒ (∀η.t1η=∅) or · · · or (∀η.tnη=∅)

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 27/27

slide-103
SLIDE 103

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Convexity and parametricity?

In reality, the condition to be used is the generalization to n types: ∀η.(t1η=∅ or · · · or tnη=∅) ⇐ ⇒ (∀η.t1η=∅) or · · · or (∀η.tnη=∅) The big question What is the relation of the condition above with parametricity? Is it a language-independent semantic characterization of it?

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 27/27

slide-104
SLIDE 104

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Convexity and parametricity?

In reality, the condition to be used is the generalization to n types: ∀η.(t1η=∅ or · · · or tnη=∅) ⇐ ⇒ (∀η.t1η=∅) or · · · or (∀η.tnη=∅) The big question What is the relation of the condition above with parametricity? Is it a language-independent semantic characterization of it? Two examples of uniformity: (t1× × ×...× × ×tn) is empty if and only if exists at least one ti empty Definability in the second-order typed λ-calculus harnesses expressions to behave uniformity. Similarly, convexity semantically harnesses the denotations of expressions and forces them to behave uniformly.

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 27/27

slide-105
SLIDE 105

logoP7

  • 1. Motivations – 2. Semantic subtyping
  • 3. Polymorphic extension
  • 4. Examples
  • 5. Subtyping algorithm
  • 6. New directions

ICFP’11

Convexity and parametricity?

In reality, the condition to be used is the generalization to n types: ∀η.(t1η=∅ or · · · or tnη=∅) ⇐ ⇒ (∀η.t1η=∅) or · · · or (∀η.tnη=∅) The big question What is the relation of the condition above with parametricity? Is it a language-independent semantic characterization of it? Two examples of uniformity: (t1× × ×...× × ×tn) is empty if and only if exists at least one ti empty Definability in the second-order typed λ-calculus harnesses expressions to behave uniformity. Similarly, convexity semantically harnesses the denotations of expressions and forces them to behave uniformly. ... we have strong flavors of parametricity

Giuseppe Castagna and Zhiwu Xu Set-theoretic Foundation of Parametric Polymorphism and Subtyping 27/27