Introduction 1 Static semantics 2 Syntax Instantiation Typing - - PowerPoint PPT Presentation

introduction
SMART_READER_LITE
LIVE PREVIEW

Introduction 1 Static semantics 2 Syntax Instantiation Typing - - PowerPoint PPT Presentation

Elaboration of e MLF into x MLF Introduction Static semantics Dynamic semantics Introduction 1 Static semantics 2 Syntax Instantiation Typing Examples Dynamic semantics 3 Reduction Examples Properties Elaboration of e MLF into x MLF


slide-1
SLIDE 1

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

1

Introduction

2

Static semantics Syntax Instantiation Typing Examples

3

Dynamic semantics Reduction Examples Properties

4

Elaboration of eMLF into xMLF

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 1 / 22

slide-2
SLIDE 2

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

System F with explicit type-level retyping functions

Didier R´ emy

INRIA Paris - Rocquencourt

IFIP WG 2.8 Based on joint work with Boris Yakobowski

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 2 / 22

slide-3
SLIDE 3

An internal language for MLF

slide-4
SLIDE 4

This is not half-baked work but half of baked work thus, I shall be short, and I will not show you any graphs.

slide-5
SLIDE 5

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Prelude About MLF

MLF smoothly combines System-F first-class polymorphism with ML-style type inference and requires very few type annotations—only on parameters

  • f functions that are used polymorphically.

MLF type inference crucially relies on type generalization for polymorphism explicit introduction, which is applied at every subexpression and not only at let-bindings. Therefore...

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 15 / 22

slide-6
SLIDE 6

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Prelude About MLF

MLF smoothly combines System-F first-class polymorphism with ML-style type inference and requires very few type annotations—only on parameters

  • f functions that are used polymorphically.

MLF type inference crucially relies on type generalization for polymorphism explicit introduction, which is applied at every subexpression and not only at let-bindings. Therefore...

MLF ♥ ML ∧ ML ♥ MLF

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 25 / 22

slide-7
SLIDE 7

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Motivation

A fair question by Simon P.J. . . . in Island: What would be an internal language for MLF ? Type soundness for MLF proved for the original version, but a bit tricky, using some intermediate more implicitly-typed version (no inference) it showed preservation of typability during reduction, but failed to preserve the typing derivation. it assumed that no reduction occurred under λ’s. type soundness has never been proved for the most general version.

  • Also. . .

Better understand instance bounded quantification, without having to bother about type inference.

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 6 / 22

slide-8
SLIDE 8

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

The example of choice

choice : ∀ (β) β → β → β

  • Λ(β) λ(x : β) λ(y : β) if true then x else y

id : ∀ (α) α → α

  • Λ(α) λ(x : α) x

choice id : (∀ (α) α → α) → (∀ (α) α → α) : ∀ (α) (α → α) → (α → α) :

?

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 17 / 22

slide-9
SLIDE 9

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

The example of choice

choice : ∀ (β) β → β → β

  • Λ(β) λ(x : β) λ(y : β) if true then x else y

id : ∀ (α) α → α

  • Λ(α) λ(x : α) x

choice id : (∀ (α) α → α) → (∀ (α) α → α) : ∀ (α) (α → α) → (α → α) : ∀ (α ∀ (α) α → α) β → β

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 27 / 22

slide-10
SLIDE 10

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

The example of choice

choice : ∀ (β) β → β → β

  • Λ(β) λ(x : β) λ(y : β) if true then x else y

id : ∀ (α) α → α

  • Λ(α) λ(x : α) x

choice id : (∀ (α) α → α) → (∀ (α) α → α) : ∀ (α) (α → α) → (α → α) : ∀ (α ∀ (α) α → α) β → β

  • ?

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 37 / 22

slide-11
SLIDE 11

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

The example of choice

choice : ∀ (β) β → β → β

  • Λ(β) λ(x : β) λ(y : β) if true then x else y

id : ∀ (α) α → α

  • Λ(α) λ(x : α) x

choice id : (∀ (α) α → α) → (∀ (α) α → α) : ∀ (α) (α → α) → (α → α) : ∀ (α ∀ (α) α → α) β → β

  • Λ(β ∀ (α) α → α) choice
  • id
  • Didier R´

emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 47 / 22

slide-12
SLIDE 12

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

The example of choice

choice : ∀ (β) β → β → β

  • Λ(β) λ(x : β) λ(y : β) if true then x else y

id : ∀ (α) α → α

  • Λ(α) λ(x : α) x

choice id : (∀ (α) α → α) → (∀ (α) α → α) : ∀ (α) (α → α) → (α → α) : ∀ (α ∀ (α) α → α) β → β

  • Λ(β ∀ (α) α → α) choice β
  • id (!β)
  • Didier R´

emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 57 / 22

slide-13
SLIDE 13

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

The example of choice

choice : ∀ (β) β → β → β

  • Λ(β) λ(x : β) λ(y : β) if true then x else y

id : ∀ (α) α → α

  • Λ(α) λ(x : α) x

choice id : (∀ (α) α → α) → (∀ (α) α → α) : ∀ (α) (α → α) → (α → α) : ∀ (α ∀ (α) α → α) β → β

  • Λ(β ∀ (α) α → α) choice (∀ ( β); )
  • id (!β)
  • Didier R´

emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 67 / 22

slide-14
SLIDE 14

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

The example of choice

choice : ∀ (β) β → β → β

  • Λ(β) λ(x : β) λ(y : β) if true then x else y

id : ∀ (α) α → α

  • Λ(α) λ(x : α) x

choice id : (∀ (α) α → α) → (∀ (α) α → α) : ∀ (α) (α → α) → (α → α) : ∀ (α ∀ (α) α → α) β → β

  • Λ(β ∀ (α) α → α) choice (∀ ( β); )
  • β → β → β
  • id (!β)

β

  • Didier R´

emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 77 / 22

slide-15
SLIDE 15

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Syntax System F

Types τ ::= | α | τ → τ | ∀ (α ) τ φ ::= τ Terms a ::= | x | λ(x : τ) a | a a | Λ(α ) a | a φ | let x = a in a

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 18 / 22

slide-16
SLIDE 16

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Syntax MLF

Types τ ::= | α | τ → τ | ∀ (α τ ) τ | ⊥ φ ::= τ Terms a ::= | x | λ(x : τ) a | a a | Λ(α τ ) a | a φ | let x = a in a

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 28 / 22

slide-17
SLIDE 17

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Syntax Instantiations

Types τ ::= | α | τ → τ | ∀ (α τ ) τ | ⊥ φ ::= τ | !α | ∀ ( φ) | ∀ (α ) φ |

  • |
  • |

φ; φ |

1

Terms a ::= | x | λ(x : τ) a | a a | Λ(α τ ) a | a φ | let x = a in a

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 38 / 22

slide-18
SLIDE 18

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Instantiation as a relation

Under

Γ, α τ ⊢ φ : τ1 ≤ τ2 Γ ⊢ ∀ (α ) φ : ∀ (α τ) τ1 ≤ ∀ (α τ) τ2

Bot

Γ ⊢ τ : ⊥ ≤ τ

Inside

Γ ⊢ φ : τ1 ≤ τ2 Γ ⊢ ∀ ( φ) : ∀ (α τ1) τ ≤ ∀ (α τ2) τ

Abstr

α τ ∈ Γ Γ ⊢ !α : τ ≤ α

Elim

Γ ⊢ : ∀ (α τ) τ ′ ≤ τ ′{α ← τ}

Id

Γ ⊢

1 : τ ≤ τ

Intro

α / ∈ ftv(τ) Γ ⊢ : τ ≤ ∀ (α ⊥) τ

Comp

Γ ⊢ φ1 : τ1 ≤ τ2 Γ ⊢ φ2 : τ2 ≤ τ3 Γ ⊢ φ1; φ2 : τ1 ≤ τ3

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 9 / 22

slide-19
SLIDE 19

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Instantiation as a function If Γ ⊢ φ : τ ≤ τ ′ then τ φ = τ ′

τ (!α) = α ⊥ (τ) = τ τ (

1)

= τ τ () = ∀ (α ⊥) τ α / ∈ ftv(τ) τ (φ1; φ2) = (τ (φ1) ) (φ2) (∀ (α τ) τ ′) () = τ ′{α ← τ} (∀ (α τ) τ ′) (∀ ( φ)) = ∀ (α τ (φ) ) τ ′ (∀ (α τ) τ ′) (∀ (α ) φ) = ∀ (α τ) (τ ′ (φ) )

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 110 / 22

slide-20
SLIDE 20

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Instantiation as a function If Γ ⊢ φ : τ ≤ τ ′ then τ φ = τ ′

τ (!α) = α

  • mitting α τ ∈ Γ

⊥ (τ) = τ τ (

1)

= τ τ () = ∀ (α ⊥) τ α / ∈ ftv(τ) τ (φ1; φ2) = (τ (φ1) ) (φ2) (∀ (α τ) τ ′) () = τ ′{α ← τ} (∀ (α τ) τ ′) (∀ ( φ)) = ∀ (α τ (φ) ) τ ′ (∀ (α τ) τ ′) (∀ (α ) φ) = ∀ (α τ) (τ ′ (φ) ) The functional view is complete, but sound only for well-typed instantiations.

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 210 / 22

slide-21
SLIDE 21

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Typing rules

Var x : τ ∈ Γ Γ ⊢ x : τ Abs Γ, x : τ ⊢ a : τ ′ Γ ⊢ λ(x : τ) a : τ → τ ′ App Γ ⊢ a1 : τ2 → τ1 Γ ⊢ a2 : τ2 Γ ⊢ a1 a2 : τ1

TAbs Γ, α τ ′ ⊢ a : τ α / ∈ ftv(Γ) Γ ⊢ Λ( α τ ′ ) a : ∀ ( α τ ′ ) τ TApp Γ ⊢ a : τ Γ ⊢ φ : τ ≤ τ ′ Γ ⊢ a ( φ ) : τ ′

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 11 / 22

slide-22
SLIDE 22

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Examples

Assume: τmin ∀ (α ⊥) α → α → α τcp ∀ (α ⊥) α → α → bool τand bool → bool → bool φ ∀ ( bool); = bool with sugar τ

  • (∀ ( τ); )

Then: φ : τmin ≤ τand φ : τcp ≤ τand Assume: τK

  • ∀ (α ⊥) ∀ (β ⊥) α → β → α

φ′ ∀ (α ) (∀ ( α); ) = ∀ (α ) α Then: φ′ : τK ≤ τmin

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 12 / 22

slide-23
SLIDE 23

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Back to choice

Verify id Λ(α ⊥) λ(x : α) x : ∀ (α ⊥) α → α

  • τid

choice Λ(β ⊥) λ(x : β) λ(y : β) x : ∀ (β ⊥) β → β → β choice id Λ(β τid) choice β (id (!β)) : ∀ (β τid) β → β Specializations choice id : (∀ (α ⊥) α → α) → (∀ (α ⊥) α → α) choice id (; ∀ (α ) (∀ ( α); )) : ∀ (α ⊥) (α → α) → α → α − → Λ(α) choice id (∀ ( α); )

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 13 / 22

slide-24
SLIDE 24

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction contexts E ::= [ · ] | E φ | λ(x : τ) E | Λ(α τ) E | E a | a E | let x = E in a | let x = a in E

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 14 / 22

slide-25
SLIDE 25

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Term reduction

(λ(x : τ) a1) a2 − → a1{x ← a2} let x = a2 in a1 − → a1{x ← a2} a

1

− → a a (φ; φ′) − → a φ (φ′) a − → Λ(α ⊥) a α / ∈ ftv(τ) (Λ(α τ) a) − → a{!α ←

1}{α ← τ}

(Λ(α τ) a) (∀ (α ) φ) − → Λ(α τ) (a φ) (Λ(α τ) a) (∀ ( φ)) − → Λ(α τ φ) a{!α ← φ; !α} E[a] − → E[a′] if a − → a′

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 15 / 22

slide-26
SLIDE 26

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Contains System F as a subsystem (Λ(α) a) τ = (Λ(α ⊥) a) (∀ ( τ); ) − → (Λ(α ⊥) a) (∀ ( τ)) () − → (Λ(α ⊥ (τ)) a{!α ← τ; !α}) () = (Λ(α τ) a) () − → a{α ← τ}

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 16 / 22

slide-27
SLIDE 27

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

(Λ(β σ) choice β id (!β)) (; ∀ (γ ) (∀ (γ); ))

a (φ; φ′) − → a φ (φ′) (ι-Seq)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 117 / 22

slide-28
SLIDE 28

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

(Λ(β σ) choice β id (!β)) () (∀ (γ ) (∀ (γ); ))

a − → Λ(α ⊥) a α / ∈ ftv(τ) (ι-Intro)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 217 / 22

slide-29
SLIDE 29

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

(Λ(α ⊥) Λ(β σ) choice β id (!β)) (∀ (γ ) (∀ ( γ); ))

(Λ(α τ) a) (∀ (α ) φ) − → Λ(α τ) (a φ) (ι-Under)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 317 / 22

slide-30
SLIDE 30

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥)

  • Λ(β σ) choice β id (!β)
  • (∀ ( α); )

a (φ; φ′) − → a φ (φ′) (ι-Seq)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 417 / 22

slide-31
SLIDE 31

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥)

  • Λ(β σ) choice β id (!β)
  • (∀ ( α)) ()

(Λ(α τ) a) (∀ ( φ)) − → Λ(α τ φ) a{!α ← φ; !α} (ι-Inside)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 517 / 22

slide-32
SLIDE 32

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥)

  • Λ(β σ α) choice β id (!β)
  • {!β ← α; !β} ()

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 617 / 22

slide-33
SLIDE 33

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥)

  • Λ(β α → α) choice β id (α; !β)
  • ()

(Λ(α τ) a) − → a{!α ←

1}{α ← τ}

(ι-Elim)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 717 / 22

slide-34
SLIDE 34

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥)

  • choice β id (α; !β)
  • {!β ←
1}{β ← α → α}

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 817 / 22

slide-35
SLIDE 35

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥) choice α → α id (α;

1)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 917 / 22

slide-36
SLIDE 36

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥) (Λ(β) λ(x : β) λ(y : β) if true then x else y) α → α (Λ(α) λ(x : α) x) (α;

1)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 1017 / 22

slide-37
SLIDE 37

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥) (Λ(β) λ(x : β) λ(y : β) if true then x else y) α → α (λ(x : α) x)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 1117 / 22

slide-38
SLIDE 38

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥) (Λ(β) λ(x : β) λ(y : β) if true then x else y) α → α (Λ(α) λ(x : α) x) α (

1)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 1217 / 22

slide-39
SLIDE 39

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥) (λ(x : α → α) λ(y : α → α) if true then x else y) (λ(x : α) x)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 1317 / 22

slide-40
SLIDE 40

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Reduction of choice id ◮ ◮ skip ◭ back

Λ(α ⊥) λ(y : α → α) if true then λ(x : α) x else y

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 1417 / 22

slide-41
SLIDE 41

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Properties of reduction Reduction in any context

It is confluent on well-typed terms (Reduction of ill-typed terms may block on type errors while some

  • ther reduction path may jump over the type error)

It should be terminating (but we have not proved it). It is type preserving.

Call-by-value and call-by-name reduction strategies

Subject reduction holds, Progress holds.

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 18 / 22

slide-42
SLIDE 42

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Elaboration of eMLF into xMLF Type preserving and semantics preserving translation

This ensures type soundness of eMLF. No computational overhead (by comparisson with translating eMLF into System F) The translation Can be computed during inference by instrumenting the constraint solver. I will save you the details...

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 19 / 22

slide-43
SLIDE 43

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Elaboration of eMLF into xMLF Elaboration is not surjective

xMLF is strictly more expressive than eMLF! (there are terms of xMLF that do not have any counterpart in eMLF) τ0

  • ∀ (α τ) ∀ (β α) β → α

τid

  • ∀ (α τ) α → α

See more?

In eMLF τ0 = τid Good choice for type inference In xMLF τ0 ≤ τid (strictly) Natural choice otherwise. The subset of xMLF that is the target of eMLF is stable by reduction. (But its specification, via a restriction of typing of instantiations, is not very natural)

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 20 / 22

slide-44
SLIDE 44

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Conclusion The MLF trilogy eMLF

type inference

iMLF

Curry Style

xMLF

Church Style

Beyond MLF

Is there a language of coercions that is an extension of both xMLF and Fη?

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 21 / 22

slide-45
SLIDE 45

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Epilogue The MLF drama

MLF ML Haskell

♥ ♥

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 122 / 22

slide-46
SLIDE 46

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Epilogue The MLF drama

MLF ML Haskell

♥ ♥ ♥

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 222 / 22

slide-47
SLIDE 47

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Epilogue The MLF drama

MLF ML Haskell

♥ ♥ ♥

¬♥

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 322 / 22

slide-48
SLIDE 48

Introduction Static semantics Dynamic semantics Elaboration of eMLF into xMLF

Epilogue The MLF drama

MLF ML Haskell

♥ ♥ ♥

¬♥

?

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 422 / 22

slide-49
SLIDE 49
slide-50
SLIDE 50

Fη Expressiveness

Appendix

5

6

Expressiveness

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 24 / 22

slide-51
SLIDE 51

Fη Expressiveness

Fη : system F with retyping functions

Definition Fη is the closure of F by η-conversion. Typechecking is as in F with the type containment rule Γ ⊢ a : τ τ ⊲ τ ′ Γ ⊢ a : τ Type containment ⊲ is the smallest reflexive, transitive relation that is covariant on all constructors except on the left of arrows where it is contravariant, ∀ (α) τ ⊲ ∀ (α′) τ{α ← τ ′} whenever α′ / ∈ ftv(∀ (α) τ), ∀ distributes over →, i.e. ∀ (α) (τ → τ ′) ⊲ ∀ (α) τ → ∀ (α) τ ′. Property τ ⊲ τ ′ if and only if there exists a ∈ F of type τ → τ ′ that βη-reduces to the identity; s is called a retyping function.

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 25 / 22

slide-52
SLIDE 52

Fη Expressiveness

Good

Fη allows implicit coercions of type expressions, according to variances: type-expressions in covariant possitions can be instantiated. type-expressions in contracovariant possitions can be generalized. Fη has more-principal types and more principal-types than System-F. For instance, in Fη we have ∀ (α)

  • (α → α) → (α → α)
  • ≤ (∀ (α) α → α) → (∀ (α) α → α)

Still

Fη does not allow simultaneous instantiations of subterms. In Fη, there is no counterpart to the MLF type: ∀ (β τid) β → β → β

eMLF and Fη instance relations are incomparable

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 26 / 22

slide-53
SLIDE 53

Fη Expressiveness

xMLF ⊆ eMLF Intuition ◭ back

In iMLF: τ0

  • ∀ (α τ) ∀ (β α) β → α

τid

  • ∀ (α τ) α → α

[ [τ0] ] = [ [τid] ] = {τ ′ → τ ′ | τ ≤ τ ′} [ [∀ (β τ) β → τ] ] = {τ ′ → τ | τ ≤ τ ′} In xMLF: [ [τ0] ] = {τ ′′ → τ ′ | τ ≤ τ ′ ≤ τ ′′} In graphical notation τ0 cannot be written—aliases must be inlined (substituted).

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 27 / 22

slide-54
SLIDE 54

Fη Expressiveness

xMLF ⊆ eMLF Example ◭ back

In xMLF choice may be given types τ ′

ch

  • ∀ (α) ∀ (α′ α) ∀ (α′′ α′) α → α′ → α′′

τ ′′

ch

  • ∀ (α) ∀ (α′ α) ∀ (α′′ α) α′ → α → α′′

which are incomparable and both more general than: τch

  • ∀ (α) α → α → α

Typing choice with τch or τ ′

ch does not allow to apply choice to more

  • arguments. However, it allows to pass choice to a function that expects an

argument of both type τ1 → τ ′

1 → τ ′′ 1 and τ ′ 2 → τ ′ 2 → τ ′′ 2 with τi ≤ τ ′ i ≤ τ ′′ i

for i in {1, 2}. Here, the type τ ′

ch may be recovered from the type τch by η-expansion, as:

Λ(α) Λ(β α) Λ(γ β) λ(x : α) λ(y : β) choice γ (x (!β; !γ)) (y (!γ))

Didier R´ emy (INRIA Paris - Rocquencourt) Explicit type-level retyping functions June 2008 28 / 22