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