A call-by-value -calculus with lists and control Robbert Krebbers - - PowerPoint PPT Presentation

a call by value calculus with lists and control
SMART_READER_LITE
LIVE PREVIEW

A call-by-value -calculus with lists and control Robbert Krebbers - - PowerPoint PPT Presentation

A call-by-value -calculus with lists and control Robbert Krebbers July 08, 2012 @ CL&C Warwick, United Kingdom Problem A lot of -calculi with control have been studied: C , , , C , , and many


slide-1
SLIDE 1

A call-by-value λ-calculus with lists and control

Robbert Krebbers July 08, 2012 @ CL&C Warwick, United Kingdom

slide-2
SLIDE 2

Problem

◮ A lot of λ-calculi with control have been studied:

λC, λµ, ¯ λµ˜ µ, λC−, λ∆, and many more. . .

slide-3
SLIDE 3

Problem

◮ A lot of λ-calculi with control have been studied:

λC, λµ, ¯ λµ˜ µ, λC−, λ∆, and many more. . .

◮ Nearly all do not support data types in direct style, i.e.

◮ inductive types ◮ natural numbers ◮ lists ◮ . . .

slide-4
SLIDE 4

Problem

◮ A lot of λ-calculi with control have been studied:

λC, λµ, ¯ λµ˜ µ, λC−, λ∆, and many more. . .

◮ Nearly all do not support data types in direct style, i.e.

◮ inductive types ◮ natural numbers ◮ lists ◮ . . .

◮ Actual programming languages do support these

slide-5
SLIDE 5

My previous attempt: λµT

◮ λµ with natural numbers (`

a la G¨

  • del’s T)
slide-6
SLIDE 6

My previous attempt: λµT

◮ λµ with natural numbers (`

a la G¨

  • del’s T)

◮ Satisfies [Geuvers/Krebbers/McKinna,2012]

◮ subject reduction, confluence, strong normalization ◮ unique representation of natural numbers

◮ Exactly as expressive as G¨

  • del’s T
slide-7
SLIDE 7

My previous attempt: λµT

◮ λµ with natural numbers (`

a la G¨

  • del’s T)

◮ Satisfies [Geuvers/Krebbers/McKinna,2012]

◮ subject reduction, confluence, strong normalization ◮ unique representation of natural numbers

◮ Exactly as expressive as G¨

  • del’s T

◮ It was not quite satisfactory:

◮ call-by-name reduction with call-by-value data types

slide-8
SLIDE 8

My previous attempt: λµT

◮ λµ with natural numbers (`

a la G¨

  • del’s T)

◮ Satisfies [Geuvers/Krebbers/McKinna,2012]

◮ subject reduction, confluence, strong normalization ◮ unique representation of natural numbers

◮ Exactly as expressive as G¨

  • del’s T

◮ It was not quite satisfactory:

◮ call-by-name reduction with call-by-value data types ◮ difficult meta theory

slide-9
SLIDE 9

My previous attempt: λµT

◮ λµ with natural numbers (`

a la G¨

  • del’s T)

◮ Satisfies [Geuvers/Krebbers/McKinna,2012]

◮ subject reduction, confluence, strong normalization ◮ unique representation of natural numbers

◮ Exactly as expressive as G¨

  • del’s T

◮ It was not quite satisfactory:

◮ call-by-name reduction with call-by-value data types ◮ difficult meta theory ◮ hard to extend

slide-10
SLIDE 10

Starting point for an improved system: Herbelin’s IQCMP

◮ Incorporates the control operators catch and throw

slide-11
SLIDE 11

Starting point for an improved system: Herbelin’s IQCMP

◮ Incorporates the control operators catch and throw ◮ Convenient meta theory

slide-12
SLIDE 12

Starting point for an improved system: Herbelin’s IQCMP

◮ Incorporates the control operators catch and throw ◮ Convenient meta theory ◮ Gives a constructive interpretation to Markov’s principle

¬¬∃x.P(x) → ∃x.P(x)

slide-13
SLIDE 13

Starting point for an improved system: Herbelin’s IQCMP

◮ Incorporates the control operators catch and throw ◮ Convenient meta theory ◮ Gives a constructive interpretation to Markov’s principle

¬¬∃x.P(x) → ∃x.P(x)

◮ However:

◮ No types like natural numbers, lists, . . . ◮ No (direct) proofs of confluence and strong normalization

slide-14
SLIDE 14

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP

slide-15
SLIDE 15

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP ◮ Primitive data type of lists and a recursor

slide-16
SLIDE 16

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP ◮ Primitive data type of lists and a recursor ◮ Fully-fledged call-by-value system

slide-17
SLIDE 17

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP ◮ Primitive data type of lists and a recursor ◮ Fully-fledged call-by-value system ◮ Satisfies the conventional meta theoretical properties:

slide-18
SLIDE 18

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP ◮ Primitive data type of lists and a recursor ◮ Fully-fledged call-by-value system ◮ Satisfies the conventional meta theoretical properties:

Subject reduction. Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

slide-19
SLIDE 19

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP ◮ Primitive data type of lists and a recursor ◮ Fully-fledged call-by-value system ◮ Satisfies the conventional meta theoretical properties:

Subject reduction. Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

  • Progress. ; ⊢ t : ρ, then t is a value or ∃t′, t → t′
slide-20
SLIDE 20

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP ◮ Primitive data type of lists and a recursor ◮ Fully-fledged call-by-value system ◮ Satisfies the conventional meta theoretical properties:

Subject reduction. Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

  • Progress. ; ⊢ t : ρ, then t is a value or ∃t′, t → t′
  • Confluence. t ։ r and t ։ s, then ∃q . r ։ q and s ։ q
slide-21
SLIDE 21

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP ◮ Primitive data type of lists and a recursor ◮ Fully-fledged call-by-value system ◮ Satisfies the conventional meta theoretical properties:

Subject reduction. Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

  • Progress. ; ⊢ t : ρ, then t is a value or ∃t′, t → t′
  • Confluence. t ։ r and t ։ s, then ∃q . r ։ q and s ։ q

Strong Normalization. Γ; ∆ ⊢ t : ρ, then no infinite t → t1 . . .

slide-22
SLIDE 22

This talk: the system λ::catch

◮ Based on Herbelin’s IQCMP ◮ Primitive data type of lists and a recursor ◮ Fully-fledged call-by-value system ◮ Satisfies the conventional meta theoretical properties:

Subject reduction. Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

  • Progress. ; ⊢ t : ρ, then t is a value or ∃t′, t → t′
  • Confluence. t ։ r and t ։ s, then ∃q . r ։ q and s ։ q

Strong Normalization. Γ; ∆ ⊢ t : ρ, then no infinite t → t1 . . .

◮ These properties are relatively easy to prove

slide-23
SLIDE 23

The system λ::catch

◮ Typing judgments `

a la Parigot’s λµ Γ; ∆ ⊢ t : ρ

slide-24
SLIDE 24

The system λ::catch

◮ Typing judgments `

a la Parigot’s λµ Γ; ∆ ⊢ t : ρ α : ψ ∈ ∆ are exceptions that may be throw

slide-25
SLIDE 25

The system λ::catch

◮ Typing judgments `

a la Parigot’s λµ Γ; ∆ ⊢ t : ρ α : ψ ∈ ∆ are exceptions that may be throw

◮ Another way to think of it: t is a proof of either

◮ ρ, or, ◮ α : ψ ∈ ∆

slide-26
SLIDE 26

The typing rules of λ::catch

The constructs of simple type theory:

x : ρ ∈ Γ Γ; ∆ ⊢ x : ρ Γ, x : σ; ∆ ⊢ t : τ Γ; ∆ ⊢ λx.t : σ → τ Γ; ∆ ⊢ t : σ → τ Γ; ∆ ⊢ s : σ Γ; ∆ ⊢ ts : τ

slide-27
SLIDE 27

The typing rules of λ::catch

The constructs of simple type theory:

x : ρ ∈ Γ Γ; ∆ ⊢ x : ρ Γ, x : σ; ∆ ⊢ t : τ Γ; ∆ ⊢ λx.t : σ → τ Γ; ∆ ⊢ t : σ → τ Γ; ∆ ⊢ s : σ Γ; ∆ ⊢ ts : τ

Constructors of the unit and list data type:

Γ; ∆ ⊢ () : ⊤ Γ; ∆ ⊢ nil : [σ] Γ; ∆ ⊢ (::) : σ → [σ] → [σ]

slide-28
SLIDE 28

The typing rules of λ::catch

The constructs of simple type theory:

x : ρ ∈ Γ Γ; ∆ ⊢ x : ρ Γ, x : σ; ∆ ⊢ t : τ Γ; ∆ ⊢ λx.t : σ → τ Γ; ∆ ⊢ t : σ → τ Γ; ∆ ⊢ s : σ Γ; ∆ ⊢ ts : τ

Constructors of the unit and list data type:

Γ; ∆ ⊢ () : ⊤ Γ; ∆ ⊢ nil : [σ] Γ; ∆ ⊢ (::) : σ → [σ] → [σ]

Primitive recursion over lists:

Γ; ∆ ⊢ lrec : ρ → (σ → [σ] → ρ → ρ) → [σ] → ρ

slide-29
SLIDE 29

The typing rules of λ::catch

The constructs of simple type theory:

x : ρ ∈ Γ Γ; ∆ ⊢ x : ρ Γ, x : σ; ∆ ⊢ t : τ Γ; ∆ ⊢ λx.t : σ → τ Γ; ∆ ⊢ t : σ → τ Γ; ∆ ⊢ s : σ Γ; ∆ ⊢ ts : τ

Constructors of the unit and list data type:

Γ; ∆ ⊢ () : ⊤ Γ; ∆ ⊢ nil : [σ] Γ; ∆ ⊢ (::) : σ → [σ] → [σ]

Primitive recursion over lists:

Γ; ∆ ⊢ lrec : ρ → (σ → [σ] → ρ → ρ) → [σ] → ρ

The control operators catch and throw:

Γ; ∆, α : ψ ⊢ t : ψ Γ; ∆ ⊢ catch α . t : ψ Γ; ∆ ⊢ t : ψ α : ψ ∈ ∆ Γ; ∆ ⊢ throw α t : τ

slide-30
SLIDE 30

The typing rules of λ::catch

The constructs of simple type theory:

x : ρ ∈ Γ Γ; ∆ ⊢ x : ρ Γ, x : σ; ∆ ⊢ t : τ Γ; ∆ ⊢ λx.t : σ → τ Γ; ∆ ⊢ t : σ → τ Γ; ∆ ⊢ s : σ Γ; ∆ ⊢ ts : τ

Constructors of the unit and list data type:

Γ; ∆ ⊢ () : ⊤ Γ; ∆ ⊢ nil : [σ] Γ; ∆ ⊢ (::) : σ → [σ] → [σ]

Primitive recursion over lists:

Γ; ∆ ⊢ lrec : ρ → (σ → [σ] → ρ → ρ) → [σ] → ρ

The control operators catch and throw:

Γ; ∆, α : ψ ⊢ t : ψ Γ; ∆ ⊢ catch α . t : ψ Γ; ∆ ⊢ t : ψ α : ψ ∈ ∆ Γ; ∆ ⊢ throw α t : τ

Important: ψ ranges over →-free types [Herbelin, 2010]

slide-31
SLIDE 31

Example: typing

; ⊢ catch α . (throw α nil) :: nil : [⊤]

slide-32
SLIDE 32

Example: typing

; ⊢ catch α . (throw α nil) :: nil : [⊤] How to think of this derivation:

  • 1. Our goal is [⊤]
slide-33
SLIDE 33

Example: typing

; α : [⊤] ⊢ (throw α nil) :: nil : [⊤] ; ⊢ catch α . (throw α nil) :: nil : [⊤] How to think of this derivation:

  • 1. Our goal is [⊤]
  • 2. We save the current continuation as α
slide-34
SLIDE 34

Example: typing

; α : [⊤] ⊢ throw α nil : ⊤ ; α : [⊤] ⊢ nil : [⊤] ; α : [⊤] ⊢ (throw α nil) :: nil : [⊤] ; ⊢ catch α . (throw α nil) :: nil : [⊤] How to think of this derivation:

  • 1. Our goal is [⊤]
  • 2. We save the current continuation as α
  • 3. We construct a singleton list

. . . leaving us to construct a term of type ⊤

slide-35
SLIDE 35

Example: typing

; α : [⊤] ⊢ nil : [⊤] ; α : [⊤] ⊢ throw α nil : ⊤ ; α : [⊤] ⊢ nil : [⊤] ; α : [⊤] ⊢ (throw α nil) :: nil : [⊤] ; ⊢ catch α . (throw α nil) :: nil : [⊤] How to think of this derivation:

  • 1. Our goal is [⊤]
  • 2. We save the current continuation as α
  • 3. We construct a singleton list

. . . leaving us to construct a term of type ⊤

  • 4. But instead we jump back to α with nil
slide-36
SLIDE 36

Reduction

Values: v, w ::= x | () | nil | (::) | (::) v | (::) v w | lrec | lrec vr | lrec vr vs | λx.r

slide-37
SLIDE 37

Reduction

Values: v, w ::= x | () | nil | (::) | (::) v | (::) v w | lrec | lrec vr | lrec vr vs | λx.r Reduction: (λx.t) v → t[x := v] lrec vr vs nil → vr lrec vr vs (vh :: vt) → vs vh vt (lrec vr vs vt)

slide-38
SLIDE 38

Reduction

Values: v, w ::= x | () | nil | (::) | (::) v | (::) v w | lrec | lrec vr | lrec vr vs | λx.r Contexts: E ::= t | v | throw β Reduction: (λx.t) v → t[x := v] lrec vr vs nil → vr lrec vr vs (vh :: vt) → vs vh vt (lrec vr vs vt) E[throw α t] → throw α t

slide-39
SLIDE 39

Reduction

Values: v, w ::= x | () | nil | (::) | (::) v | (::) v w | lrec | lrec vr | lrec vr vs | λx.r Contexts: E ::= t | v | throw β Reduction: (λx.t) v → t[x := v] lrec vr vs nil → vr lrec vr vs (vh :: vt) → vs vh vt (lrec vr vs vt) E[throw α t] → throw α t catch α . throw α t → catch α . t

slide-40
SLIDE 40

Reduction

Values: v, w ::= x | () | nil | (::) | (::) v | (::) v w | lrec | lrec vr | lrec vr vs | λx.r Contexts: E ::= t | v | throw β Reduction: (λx.t) v → t[x := v] lrec vr vs nil → vr lrec vr vs (vh :: vt) → vs vh vt (lrec vr vs vt) E[throw α t] → throw α t catch α . throw α t → catch α . t catch α . throw β v → throw β v

if α / ∈ {β} ∪ FCV(v)

slide-41
SLIDE 41

Reduction

Values: v, w ::= x | () | nil | (::) | (::) v | (::) v w | lrec | lrec vr | lrec vr vs | λx.r Contexts: E ::= t | v | throw β Reduction: (λx.t) v → t[x := v] lrec vr vs nil → vr lrec vr vs (vh :: vt) → vs vh vt (lrec vr vs vt) E[throw α t] → throw α t catch α . throw α t → catch α . t catch α . throw β v → throw β v

if α / ∈ {β} ∪ FCV(v)

catch α . v → v

if α / ∈ FCV(v)

slide-42
SLIDE 42

Example: reduction

catch α . (throw α nil) :: nil

slide-43
SLIDE 43

Example: reduction

catch α . (throw α nil) :: nil

slide-44
SLIDE 44

Example: reduction

catch α . (throw α nil) :: nil ≡ catch α . ( :: nil)[throw α nil]

slide-45
SLIDE 45

Example: reduction

catch α . (throw α nil) :: nil ≡ catch α . ( :: nil)[throw α nil]

slide-46
SLIDE 46

Example: reduction

catch α . (throw α nil) :: nil ≡ catch α . ( :: nil)[throw α nil] → catch α . throw α nil

slide-47
SLIDE 47

Example: reduction

catch α . (throw α nil) :: nil ≡ catch α . ( :: nil)[throw α nil] → catch α . throw α nil

slide-48
SLIDE 48

Example: reduction

catch α . (throw α nil) :: nil ≡ catch α . ( :: nil)[throw α nil] → catch α . throw α nil → catch α . nil

slide-49
SLIDE 49

Example: reduction

catch α . (throw α nil) :: nil ≡ catch α . ( :: nil)[throw α nil] → catch α . throw α nil → catch α . nil

slide-50
SLIDE 50

Example: reduction

catch α . (throw α nil) :: nil ≡ catch α . ( :: nil)[throw α nil] → catch α . throw α nil → catch α . nil → nil

slide-51
SLIDE 51

Why restrict to →-free types? (1)

Progress: ; ⊢ t : τ = ⇒ t is a value or ∃t′.t → t′

slide-52
SLIDE 52

Why restrict to →-free types? (1)

Progress: ; ⊢ t : τ = ⇒ t is a value or ∃t′.t → t′

◮ Without the →-free restriction, the term

catch α . λx.throw α (λy.y) : ⊤ → ⊤ would not reduce

slide-53
SLIDE 53

Why restrict to →-free types? (1)

Progress: ; ⊢ t : τ = ⇒ t is a value or ∃t′.t → t′

◮ Without the →-free restriction, the term

catch α . λx.throw α (λy.y) : ⊤ → ⊤ would not reduce

◮ Hence progress would fail

slide-54
SLIDE 54

Why restrict to →-free types? (1)

Progress: ; ⊢ t : τ = ⇒ t is a value or ∃t′.t → t′

◮ Without the →-free restriction, the term

catch α . λx.throw α (λy.y) : ⊤ → ⊤ would not reduce

◮ Hence progress would fail ◮ Note: an analogue term in the λµ-calculus

µα.[α]λx.µ .[α]λy.y does not reduce either

slide-55
SLIDE 55

Why restrict to →-free types? (2)

Consequences of progress

◮ In Herbelin’s IQCMP:

◮ If ; ⊢ t : ρ ∨ σ, then ∃t′ . ; ⊢ t′ : ρ or ; ⊢ t′ : σ ◮ If ; ⊢ t : ∃x.P(x), then ∃t′ . ; ⊢ t′ : P(t′)

slide-56
SLIDE 56

Why restrict to →-free types? (2)

Consequences of progress

◮ In Herbelin’s IQCMP:

◮ If ; ⊢ t : ρ ∨ σ, then ∃t′ . ; ⊢ t′ : ρ or ; ⊢ t′ : σ ◮ If ; ⊢ t : ∃x.P(x), then ∃t′ . ; ⊢ t′ : P(t′)

◮ In λ::catch:

◮ Unique representation of data ◮ One-to-one correspondence between closed terms of N and N

slide-57
SLIDE 57

Natural numbers

We define a type N := [⊤], with: 0 := nil S := (::) () nrec := λxrys . lrec xr (λ . xs) Notation: n := Sn0

slide-58
SLIDE 58

Inefficient predecessor

We could define pred : N → N as pred := nrec 0 (λxh . x)

slide-59
SLIDE 59

Inefficient predecessor

We could define pred : N → N as pred := nrec 0 (λxh . x) Inefficient with call-by-value reduction pred n ։ (λxh . x) n − 1 (pred n − 1)

slide-60
SLIDE 60

Inefficient predecessor

We could define pred : N → N as pred := nrec 0 (λxh . x) Inefficient with call-by-value reduction pred n ։ (λxh . x) n − 1 (pred n − 1) ։ (λh . n − 1) (pred n − 2)

  • not a value
slide-61
SLIDE 61

Inefficient predecessor

We could define pred : N → N as pred := nrec 0 (λxh . x) Inefficient with call-by-value reduction pred n ։ (λxh . x) n − 1 (pred n − 1) ։ (λh . n − 1) (pred n − 2)

  • not a value

։ (λh . n − 1) ((λh . n − 2) (pred n − 2)

  • not a value

)

slide-62
SLIDE 62

Inefficient predecessor

We could define pred : N → N as pred := nrec 0 (λxh . x) Inefficient with call-by-value reduction pred n ։ (λxh . x) n − 1 (pred n − 1) ։ (λh . n − 1) (pred n − 2)

  • not a value

։ (λh . n − 1) ((λh . n − 2) (pred n − 2)

  • not a value

) ։ . . .

slide-63
SLIDE 63

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n

slide-64
SLIDE 64

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1

slide-65
SLIDE 65

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1

slide-66
SLIDE 66

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n)

slide-67
SLIDE 67

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n)

slide-68
SLIDE 68

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n) ։ catch α . (λx . throw α x) n (lrec 0 (λ x . throw α x) n)

slide-69
SLIDE 69

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n) ։ catch α . (λx . throw α x) n (lrec 0 (λ x . throw α x) n)

slide-70
SLIDE 70

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n) ։ catch α . (λx . throw α x) n (lrec 0 (λ x . throw α x) n) ։ catch α . (throw α n) (lrec 0 (λ x . throw α x) n)

slide-71
SLIDE 71

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n) ։ catch α . (λx . throw α x) n (lrec 0 (λ x . throw α x) n) ։ catch α . (throw α n) (lrec 0 (λ x . throw α x) n) We use the rule (throw α t) r → throw α t to discard the recursive call

slide-72
SLIDE 72

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n) ։ catch α . (λx . throw α x) n (lrec 0 (λ x . throw α x) n) ։ catch α . (throw α n) (lrec 0 (λ x . throw α x) n) ։ catch α . throw α n We use the rule (throw α t) r → throw α t to discard the recursive call

slide-73
SLIDE 73

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n) ։ catch α . (λx . throw α x) n (lrec 0 (λ x . throw α x) n) ։ catch α . (throw α n) (lrec 0 (λ x . throw α x) n) ։ catch α . throw α n

slide-74
SLIDE 74

A more efficient predecessor in λ::catch

We redefine pred : N → N as pred := λn . catch α . nrec 0 (λx . throw α x) n Using catch and throw it becomes more efficient pred n + 1 ։ catch α . nrec 0 (λx . throw α x) (S n) ։ catch α . (λx . throw α x) n (lrec 0 (λ x . throw α x) n) ։ catch α . (throw α n) (lrec 0 (λ x . throw α x) n) ։ catch α . throw α n ։ n

slide-75
SLIDE 75

Example: list multiplication

◮ We want to define F : [N] → N such that

F[t1, . . . , tn] = t1 ∗ . . . ∗ tn

slide-76
SLIDE 76

Example: list multiplication

◮ We want to define F : [N] → N such that

F[t1, . . . , tn] = t1 ∗ . . . ∗ tn

◮ The straightforward definition

F := lrec 1 (λx h . x ∗ h) continues to multiply once a zero has been encountered

slide-77
SLIDE 77

Example: list multiplication

◮ We want to define F : [N] → N such that

F[t1, . . . , tn] = t1 ∗ . . . ∗ tn

◮ The straightforward definition

F := lrec 1 (λx h . x ∗ h) continues to multiply once a zero has been encountered

◮ We use control to jump out when we encounter a zero

F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x

slide-78
SLIDE 78

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

slide-79
SLIDE 79

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9]

slide-80
SLIDE 80

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9]

slide-81
SLIDE 81

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9])

slide-82
SLIDE 82

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9])

slide-83
SLIDE 83

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (lrec 1 H [0, 9])

slide-84
SLIDE 84

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (lrec 1 H [0, 9])

slide-85
SLIDE 85

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (throw α 0)

slide-86
SLIDE 86

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (throw α 0)

slide-87
SLIDE 87

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (throw α 0) ։ catch α . throw α 0

slide-88
SLIDE 88

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (throw α 0) ։ catch α . throw α 0

slide-89
SLIDE 89

Example: list multiplication (continued)

The definition of list multiplication: F := λl . catch α . lrec 1 H l H := λx . nrec (throw α 0) (λy h . S y ∗ h) x A computation of F [4, 0, 9]:

։ catch α . lrec 1 H [4, 0, 9] ։ catch α . nrec (throw α 0) (λy h . S y ∗ h) 4 (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (lrec 1 H [0, 9]) ։ catch α . (λh . 4 ∗ h) (throw α 0) ։ catch α . throw α 0 ։ 0

slide-90
SLIDE 90

Properties of λ::catch

◮ Subject reduction.

Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

◮ A standard substitution lemma is needed ◮ Induction on the structure of t → t′

slide-91
SLIDE 91

Properties of λ::catch

◮ Subject reduction.

Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

◮ A standard substitution lemma is needed ◮ Induction on the structure of t → t′

◮ Progress.

; ⊢ t : ρ, then t is a value or ∃t′, t → t′

◮ A simple generalization is needed ◮ Induction on the typing judgment.

slide-92
SLIDE 92

Properties of λ::catch

◮ Subject reduction.

Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

◮ A standard substitution lemma is needed ◮ Induction on the structure of t → t′

◮ Progress.

; ⊢ t : ρ, then t is a value or ∃t′, t → t′

◮ A simple generalization is needed ◮ Induction on the typing judgment.

◮ Confluence.

t ։ r and t ։ s, then ∃q . r ։ q and s ։ q

slide-93
SLIDE 93

Properties of λ::catch

◮ Subject reduction.

Γ; ∆ ⊢ t : ρ and t → t′, then Γ; ∆ ⊢ t′ : ρ

◮ A standard substitution lemma is needed ◮ Induction on the structure of t → t′

◮ Progress.

; ⊢ t : ρ, then t is a value or ∃t′, t → t′

◮ A simple generalization is needed ◮ Induction on the typing judgment.

◮ Confluence.

t ։ r and t ։ s, then ∃q . r ։ q and s ։ q

◮ Strong Normalization.

Γ; ∆ ⊢ t : ρ, then no infinite t → t1 . . .

slide-94
SLIDE 94

Parallel reduction

Usual approach [Tait/Martin-L¨

  • f]
  • 1. Define a parallel reduction ⇒
  • 2. Prove that ⇒ is confluent
  • 3. Prove that t1 → t2 implies t1 ⇒ t2
  • 4. Prove that t1 ⇒ t2 implies t1 ։ t2
slide-95
SLIDE 95

Parallel reduction

Usual approach [Tait/Martin-L¨

  • f]
  • 1. Define a parallel reduction ⇒
  • 2. Prove that ⇒ is confluent
  • 3. Prove that t1 → t2 implies t1 ⇒ t2
  • 4. Prove that t1 ⇒ t2 implies t1 ։ t2

For the ordinary λ-calculus x ⇒ x t ⇒ t′ λx.t ⇒ λx.t′ t ⇒ t′ r ⇒ r′ tr ⇒ t′r′ t ⇒ t′ r ⇒ r′ (λx.t)r ⇒ t′[x := r′]

slide-96
SLIDE 96

Parallel reduction for λ::catch

◮ Consider the naive rule for throw

t ⇒ t′ E[throw α t] ⇒ throw α t′

slide-97
SLIDE 97

Parallel reduction for λ::catch

◮ Consider the naive rule for throw

t ⇒ t′ E[throw α t] ⇒ throw α t′

◮ Problem: not confluent

throw α1 (throw α2 (throw α3 (throw α4 (throw α5 x))))

  • throw α1 (throw α3 (throw α5 x))

throw α2 (throw α4 (throw α5 x))

slide-98
SLIDE 98

Parallel reduction for λ::catch

◮ Consider the naive rule for throw

t ⇒ t′ E[throw α t] ⇒ throw α t′

◮ Problem: not confluent

throw α1 (throw α2 (throw α3 (throw α4 (throw α5 x))))

  • throw α1 (throw α3 (throw α5 x))

throw α2 (throw α4 (throw α5 x))

◮ Solution: jump over a compound context

t ⇒ t′

  • E[throw α t] ⇒ throw α t′
slide-99
SLIDE 99

Complete development

Define t⋄ such that if t1 ⇒ t2, then t2 ⇒ t⋄

1 [Takahashi, 1995]

slide-100
SLIDE 100

Complete development

Define t⋄ such that if t1 ⇒ t2, then t2 ⇒ t⋄

1 [Takahashi, 1995]

Confluence of ⇒ is a direct consequence t1

  • t2

t3

slide-101
SLIDE 101

Complete development

Define t⋄ such that if t1 ⇒ t2, then t2 ⇒ t⋄

1 [Takahashi, 1995]

Confluence of ⇒ is a direct consequence t1

  • t2
  • t3
  • t⋄

1

slide-102
SLIDE 102

Complete development for λ::catch

((λx.t) v)⋄ := t⋄[x := v⋄] ( E[throw α t])⋄ := throw α t⋄ if t ≡ throw γ s (catch α . throw α t)⋄ := catch α . t⋄ (catch α . throw β v)⋄ := throw β v⋄ if α /

∈ {β} ∪ FCV(v)

(catch α . v)⋄ := v⋄

if α / ∈ FCV(v)

(lrec vr vs nil)⋄ := v⋄

r

(lrec vr vs (vh :: vt))⋄ := v⋄

s v⋄ h v⋄ t (lrec v⋄ r v⋄ s v⋄ t )

. . .

slide-103
SLIDE 103

Strong Normalization

The interpretation [ [ρ] ] of a type ρ is defined as: [ [⊤] ] := SN [ [σ → τ] ] := {t | ∀s ∈ [ [σ] ] . ts ∈ [ [τ] ]}

slide-104
SLIDE 104

Strong Normalization

The interpretation [ [ρ] ] of a type ρ is defined as: [ [⊤] ] := SN [ [σ → τ] ] := {t | ∀s ∈ [ [σ] ] . ts ∈ [ [τ] ]} [ [[σ]] ] :=

slide-105
SLIDE 105

Strong Normalization

The interpretation [ [ρ] ] of a type ρ is defined as: [ [⊤] ] := SN [ [σ → τ] ] := {t | ∀s ∈ [ [σ] ] . ts ∈ [ [τ] ]} [ [[σ]] ] := SN

slide-106
SLIDE 106

Strong Normalization

The interpretation [ [ρ] ] of a type ρ is defined as: [ [⊤] ] := SN [ [σ → τ] ] := {t | ∀s ∈ [ [σ] ] . ts ∈ [ [τ] ]} [ [[σ]] ] := SN ∩ L[

[σ] ]

where for a set of terms S, the set of terms LS is defined as ∀v w . if t ։ v :: w then v ∈ S and w ∈ LS t ∈ LS

slide-107
SLIDE 107

Strong Normalization

The interpretation [ [ρ] ] of a type ρ is defined as: [ [⊤] ] := SN [ [σ → τ] ] := {t | ∀s ∈ [ [σ] ] . ts ∈ [ [τ] ]} [ [[σ]] ] := SN ∩ L[

[σ] ]

where for a set of terms S, the set of terms LS is defined as ∀v w . if t ։ v :: w then v ∈ S and w ∈ LS t ∈ LS Key lemmas

◮ [

[ψ] ] = SN for ψ →-free

slide-108
SLIDE 108

Strong Normalization

The interpretation [ [ρ] ] of a type ρ is defined as: [ [⊤] ] := SN [ [σ → τ] ] := {t | ∀s ∈ [ [σ] ] . ts ∈ [ [τ] ]} [ [[σ]] ] := SN ∩ L[

[σ] ]

where for a set of terms S, the set of terms LS is defined as ∀v w . if t ։ v :: w then v ∈ S and w ∈ LS t ∈ LS Key lemmas

◮ [

[ψ] ] = SN for ψ →-free

◮ If r ∈ [

[ψ] ], then catch α . r ∈ [ [ψ] ]

slide-109
SLIDE 109

Strong Normalization

The interpretation [ [ρ] ] of a type ρ is defined as: [ [⊤] ] := SN [ [σ → τ] ] := {t | ∀s ∈ [ [σ] ] . ts ∈ [ [τ] ]} [ [[σ]] ] := SN ∩ L[

[σ] ]

where for a set of terms S, the set of terms LS is defined as ∀v w . if t ։ v :: w then v ∈ S and w ∈ LS t ∈ LS Key lemmas

◮ [

[ψ] ] = SN for ψ →-free

◮ If r ∈ [

[ψ] ], then catch α . r ∈ [ [ψ] ]

◮ If r ∈ SN and t[x := r] ∈ [

[σ] ], then (λx.t) r ∈ [ [σ] ]

slide-110
SLIDE 110

Strong Normalization

The interpretation [ [ρ] ] of a type ρ is defined as: [ [⊤] ] := SN [ [σ → τ] ] := {t | ∀s ∈ [ [σ] ] . ts ∈ [ [τ] ]} [ [[σ]] ] := SN ∩ L[

[σ] ]

where for a set of terms S, the set of terms LS is defined as ∀v w . if t ։ v :: w then v ∈ S and w ∈ LS t ∈ LS Key lemmas

◮ [

[ψ] ] = SN for ψ →-free

◮ If r ∈ [

[ψ] ], then catch α . r ∈ [ [ψ] ]

◮ If r ∈ SN and t[x := r] ∈ [

[σ] ], then (λx.t) r ∈ [ [σ] ]

◮ If x1 : ρ1, . . . , xn : ρn; ∆ ⊢ t : τ and ri ∈ [

[ρi] ] for all 1 ≤ i ≤ n, then t[x1 := r1, . . . , xn := rn] ∈ [ [τ] ]

slide-111
SLIDE 111

Future work

◮ More interesting data types

slide-112
SLIDE 112

Future work

◮ More interesting data types ◮ Pattern match and fix construct

slide-113
SLIDE 113

Future work

◮ More interesting data types ◮ Pattern match and fix construct ◮ Dynamically bound exceptions

slide-114
SLIDE 114

Future work

◮ More interesting data types ◮ Pattern match and fix construct ◮ Dynamically bound exceptions ◮ Corresponding abstract machine

slide-115
SLIDE 115

Future work

◮ More interesting data types ◮ Pattern match and fix construct ◮ Dynamically bound exceptions ◮ Corresponding abstract machine ◮ Polymorphism

slide-116
SLIDE 116

Future work

◮ More interesting data types ◮ Pattern match and fix construct ◮ Dynamically bound exceptions ◮ Corresponding abstract machine ◮ Polymorphism ◮ Dependent types

slide-117
SLIDE 117

Future work

◮ More interesting data types ◮ Pattern match and fix construct ◮ Dynamically bound exceptions ◮ Corresponding abstract machine ◮ Polymorphism ◮ Dependent types ◮ Program extraction `

a la Paulin/Letouzey