Advanced Semantics of Programming Languages Pierre C LAIRAMBAULT - - PowerPoint PPT Presentation

advanced semantics of programming languages
SMART_READER_LITE
LIVE PREVIEW

Advanced Semantics of Programming Languages Pierre C LAIRAMBAULT - - PowerPoint PPT Presentation

Advanced Semantics of Programming Languages Pierre C LAIRAMBAULT & Colin R IBA LIP - ENS de Lyon Course 01 09/11 C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 1 / 10 Naive Introduction A Naive Introduction


slide-1
SLIDE 1

Advanced Semantics of Programming Languages

Pierre CLAIRAMBAULT & Colin RIBA

LIP - ENS de Lyon

Course 01 09/11

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 1 / 10

slide-2
SLIDE 2

Naive Introduction

A Naive Introduction

(based on simple examples)

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 2 / 10

slide-3
SLIDE 3

Naive Introduction

The First Example

Consider the programs foo(f:int->int): return f(5) + f(5) and bar(f:int->int): a = f(5) return a + a

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10

slide-4
SLIDE 4

Naive Introduction

The First Example

Consider the programs foo(f:int->int): return f(5) + f(5) and bar(f:int->int): a = f(5) return a + a Are these two programs equivalent ?

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10

slide-5
SLIDE 5

Naive Introduction

The First Example

Consider the programs foo(f:int->int): return f(5) + f(5) and bar(f:int->int): a = f(5) return a + a Are these two programs equivalent ? ◮ They are not equivalent if f can access a global reference.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10

slide-6
SLIDE 6

Naive Introduction

The First Example

Consider the programs foo(f:int->int): return f(5) + f(5) and bar(f:int->int): a = f(5) return a + a Are these two programs equivalent ? ◮ They are not equivalent if f can access a global reference. ◮ They are equivalent if f behaves as a function, say f : int − → int where int is a set representing the type int.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10

slide-7
SLIDE 7

Naive Introduction

The First Example

Consider the programs foo(f:int->int): return f(5) + f(5) and bar(f:int->int): a = f(5) return a + a Are these two programs equivalent ? ◮ They are not equivalent if f can access a global reference. ◮ They are equivalent if f behaves as a function, say f : int − → int where int is a set representing the type int. Objectives of the course. ◮ Mathematical models of programming languages (denotational semantics, category theory, type systems).

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10

slide-8
SLIDE 8

Naive Introduction

The First Example

Consider the programs foo(f:int->int): return f(5) + f(5) and bar(f:int->int): a = f(5) return a + a Are these two programs equivalent ? ◮ They are not equivalent if f can access a global reference. ◮ They are equivalent if f behaves as a function, say f : int − → int where int is a set representing the type int. Objectives of the course. ◮ Mathematical models of programming languages (denotational semantics, category theory, type systems). Methodology of the course. ◮ Begin with simple approaches. ◮ Then progressively model more complex behaviours.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10

slide-9
SLIDE 9

Naive Introduction

The First Example

Consider the programs foo(f:int->int): return f(5) + f(5) and bar(f:int->int): a = f(5) return a + a Are these two programs equivalent ? ◮ They are not equivalent if f can access a global reference. ◮ They are equivalent if f behaves as a function, say f : int − → int where int is a set representing the type int. Objectives of the course. ◮ Mathematical models of programming languages (denotational semantics, category theory, type systems). Methodology of the course. ◮ Begin with simple approaches. ◮ Then progressively model more complex behaviours. Now: ◮ A naive introduction to some basic ideas.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10

slide-10
SLIDE 10

Naive Introduction

Types as Sets

◮ Assume types, say int, bool, are to be interpreted as sets int, bool.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10

slide-11
SLIDE 11

Naive Introduction

Types as Sets

◮ Assume types, say int, bool, are to be interpreted as sets int, bool. Question. ◮ Can we assume bool := {true, false} (1)

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10

slide-12
SLIDE 12

Naive Introduction

Types as Sets

◮ Assume types, say int, bool, are to be interpreted as sets int, bool. Question. ◮ Can we assume bool := {true, false} (1) Answer. ◮ Consider the non-terminating program loop (b:bool): while true: skip return true

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10

slide-13
SLIDE 13

Naive Introduction

Types as Sets

◮ Assume types, say int, bool, are to be interpreted as sets int, bool. Question. ◮ Can we assume bool := {true, false} (1) Answer. ◮ Consider the non-terminating program loop (b:bool): while true: skip return true ◮ If bool is as in (1), then we can not have loop : bool − → bool

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10

slide-14
SLIDE 14

Naive Introduction

Types as Sets

◮ Assume types, say int, bool, are to be interpreted as sets int, bool. Question. ◮ Can we assume bool := {true, false} (1) Answer. ◮ Consider the non-terminating program loop (b:bool): while true: skip return true ◮ If bool is as in (1), then we can not have loop : bool − → bool ◮ We shall therefore represent divergence and assume bool := {⊥, true, false} (⊥ “=” divergence) We can then have, as expected: loop(a) = ⊥ (for all a ∈ bool)

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10

slide-15
SLIDE 15

Naive Introduction

A Taste of Finitary PCF

Motivation. ◮ A simple language to discuss bool := {⊥, true, false}

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 5 / 10

slide-16
SLIDE 16

Naive Introduction

A Taste of Finitary PCF

Motivation. ◮ A simple language to discuss bool := {⊥, true, false} The Language of Finitary PCF. τ, σ ::= bool | σ → τ t, u ::= t u | fun x → t | true | false | if t then u else v | Ω

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 5 / 10

slide-17
SLIDE 17

Naive Introduction

A Taste of Finitary PCF

Motivation. ◮ A simple language to discuss bool := {⊥, true, false} The Language of Finitary PCF. τ, σ ::= bool | σ → τ t, u ::= t u | fun x → t | true | false | if t then u else v | Ω ◮ Purely functional language with Booleans and divergence (Ω).

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 5 / 10

slide-18
SLIDE 18

Naive Introduction

A Taste of Finitary PCF

Motivation. ◮ A simple language to discuss bool := {⊥, true, false} The Language of Finitary PCF. τ, σ ::= bool | σ → τ t, u ::= t u | fun x → t | true | false | if t then u else v | Ω ◮ Purely functional language with Booleans and divergence (Ω). We assume call-by-name evaluation: (fun x → t)u = t[u/x] if true then t else u = t if false then t else u = u

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 5 / 10

slide-19
SLIDE 19

Naive Introduction

Example. Consider the two following or programs:

  • r_l := fun a, b ->

if a then a else b vs

  • r_r := fun a, b ->

if b then b else a

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 6 / 10

slide-20
SLIDE 20

Naive Introduction

Example. Consider the two following or programs:

  • r_l := fun a, b ->

if a then a else b vs

  • r_r := fun a, b ->

if b then b else a Questions. ◮ What are the functions or_l, or_r ? ◮ Are the programs or_l and or_r equivalent ?

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 6 / 10

slide-21
SLIDE 21

Naive Introduction

Example. Consider the two following or programs:

  • r_l := fun a, b ->

if a then a else b vs

  • r_r := fun a, b ->

if b then b else a Questions. ◮ What are the functions or_l, or_r ? ◮ Are the programs or_l and or_r equivalent ? Example. Consider, for b ∈ {true, false}, the program taste_b := fun f -> if f(true, Ω) and f(Ω, true) and not(f(false, false)) then b else true

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 6 / 10

slide-22
SLIDE 22

Naive Introduction

Example. Consider the two following or programs:

  • r_l := fun a, b ->

if a then a else b vs

  • r_r := fun a, b ->

if b then b else a Questions. ◮ What are the functions or_l, or_r ? ◮ Are the programs or_l and or_r equivalent ? Example. Consider, for b ∈ {true, false}, the program taste_b := fun f -> if f(true, Ω) and f(Ω, true) and not(f(false, false)) then b else true Questions. ◮ Do we have taste_true = taste_false ? ◮ Are taste_true and taste_false equivalent ?

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 6 / 10

slide-23
SLIDE 23

Naive Introduction

A Taste of PCF

Motivation. ◮ Extend Finitary PCF with general recursion. ◮ Mathematically cleaner if an infinite type is assumed (say the natural numbers).

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 7 / 10

slide-24
SLIDE 24

Naive Introduction

A Taste of PCF

Motivation. ◮ Extend Finitary PCF with general recursion. ◮ Mathematically cleaner if an infinite type is assumed (say the natural numbers). The Language of PCF. τ, σ ::= . . . | nat t, u ::= . . . | t+1 | t-1 | z? | Y | n (for each n ∈ N) ◮ Y is a fixpoint combinator: Y t = t (Y t)

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 7 / 10

slide-25
SLIDE 25

Naive Introduction

A Taste of PCF

Motivation. ◮ Extend Finitary PCF with general recursion. ◮ Mathematically cleaner if an infinite type is assumed (say the natural numbers). The Language of PCF. τ, σ ::= . . . | nat t, u ::= . . . | t+1 | t-1 | z? | Y | n (for each n ∈ N) ◮ Y is a fixpoint combinator: Y t = t (Y t) Examples. ◮ We could have defined Ω := Y(fun x → x)

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 7 / 10

slide-26
SLIDE 26

Naive Introduction

A Taste of PCF

Motivation. ◮ Extend Finitary PCF with general recursion. ◮ Mathematically cleaner if an infinite type is assumed (say the natural numbers). The Language of PCF. τ, σ ::= . . . | nat t, u ::= . . . | t+1 | t-1 | z? | Y | n (for each n ∈ N) ◮ Y is a fixpoint combinator: Y t = t (Y t) Examples. ◮ We could have defined Ω := Y(fun x → x) ◮ Addition add 0 u = u add t+1 u = (add t u)+1

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 7 / 10

slide-27
SLIDE 27

Naive Introduction

A Taste of PCF

Motivation. ◮ Extend Finitary PCF with general recursion. ◮ Mathematically cleaner if an infinite type is assumed (say the natural numbers). The Language of PCF. τ, σ ::= . . . | nat t, u ::= . . . | t+1 | t-1 | z? | Y | n (for each n ∈ N) ◮ Y is a fixpoint combinator: Y t = t (Y t) Examples. ◮ We could have defined Ω := Y(fun x → x) ◮ Addition add 0 u = u add t+1 u = (add t u)+1 can be defined as add := Y add_rec where add_rec := fun f, x, y -> if (z? x) then y else (f x-1 y)+1

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 7 / 10

slide-28
SLIDE 28

Naive Introduction

A Denotational Semantics for PCF ?

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 8 / 10

slide-29
SLIDE 29

Naive Introduction

A Denotational Semantics for PCF ?

We Would Like ◮ each type τ to be interpreted as a set τ,

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 8 / 10

slide-30
SLIDE 30

Naive Introduction

A Denotational Semantics for PCF ?

We Would Like ◮ each type τ to be interpreted as a set τ, ◮ a program t of type say σ → τ to be interpreted as a function t : σ − → τ

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 8 / 10

slide-31
SLIDE 31

Naive Introduction

A Denotational Semantics for PCF ?

We Would Like ◮ each type τ to be interpreted as a set τ, ◮ a program t of type say σ → τ to be interpreted as a function t : σ − → τ Difficulty. ◮ Equation Y t = t (Y t) imposes Y : (S → S) − → S

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 8 / 10

slide-32
SLIDE 32

Naive Introduction

A Denotational Semantics for PCF ?

We Would Like ◮ each type τ to be interpreted as a set τ, ◮ a program t of type say σ → τ to be interpreted as a function t : σ − → τ Difficulty. ◮ Equation Y t = t (Y t) imposes Y : (S → S) − → S Traditional Solution. ◮ Restrict S → S to the continuous functions for a suitable topology (cpos, Scott domains, etc).

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 8 / 10

slide-33
SLIDE 33

Naive Introduction

A Denotational Semantics for PCF ?

We Would Like ◮ each type τ to be interpreted as a set τ, ◮ a program t of type say σ → τ to be interpreted as a function t : σ − → τ Difficulty. ◮ Equation Y t = t (Y t) imposes Y : (S → S) − → S Traditional Solution. ◮ Restrict S → S to the continuous functions for a suitable topology (cpos, Scott domains, etc). Gödel’s System T. ◮ Restrict Y to recursion over N: rec u v 0 = u rec u v t+1 = v t (rec u v t)

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 8 / 10

slide-34
SLIDE 34

Naive Introduction

A Denotational Semantics for PCF ?

We Would Like ◮ each type τ to be interpreted as a set τ, ◮ a program t of type say σ → τ to be interpreted as a function t : σ − → τ Difficulty. ◮ Equation Y t = t (Y t) imposes Y : (S → S) − → S Traditional Solution. ◮ Restrict S → S to the continuous functions for a suitable topology (cpos, Scott domains, etc). Gödel’s System T. ◮ Restrict Y to recursion over N: rec u v 0 = u rec u v t+1 = v t (rec u v t) ◮ Allows to see important basic techniques in a simple setting.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 8 / 10

slide-35
SLIDE 35

Outline

Rough Outline

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 9 / 10

slide-36
SLIDE 36

Outline

Indicative Outline

Courses 1–6: (C. RIBA) ◮ Set-theoretic semantics of System T. ◮ Denotational semantics of PCF (cpos, logical relations). ◮ Further topics among:

◮ Polymorphism (Girard-Reynolds System F). ◮ Recursive types. ◮ Intersection types. ◮ Scott domains and PCF definability. ◮ Results on the set-theoretic semantics of the simply-typed λ-calculus.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 10 / 10

slide-37
SLIDE 37

Outline

Indicative Outline

Courses 1–6: (C. RIBA) ◮ Set-theoretic semantics of System T. ◮ Denotational semantics of PCF (cpos, logical relations). ◮ Further topics among:

◮ Polymorphism (Girard-Reynolds System F). ◮ Recursive types. ◮ Intersection types. ◮ Scott domains and PCF definability. ◮ Results on the set-theoretic semantics of the simply-typed λ-calculus.

Courses 7–12: (P . CLAIRAMBAULT) ◮ Categories, functors and natural transformations. ◮ Cartesian closed categories and the λ-calculus. ◮ Monads. ◮ Further topics among:

◮ Categorical models of linear logic. ◮ Game semantics.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 10 / 10

slide-38
SLIDE 38

Outline

Indicative Outline

Courses 1–6: (C. RIBA) ◮ Set-theoretic semantics of System T. ◮ Denotational semantics of PCF (cpos, logical relations). ◮ Further topics among:

◮ Polymorphism (Girard-Reynolds System F). ◮ Recursive types. ◮ Intersection types. ◮ Scott domains and PCF definability. ◮ Results on the set-theoretic semantics of the simply-typed λ-calculus.

Courses 7–12: (P . CLAIRAMBAULT) ◮ Categories, functors and natural transformations. ◮ Cartesian closed categories and the λ-calculus. ◮ Monads. ◮ Further topics among:

◮ Categorical models of linear logic. ◮ Game semantics.

Courses 13–: Survey of Some Active Research Topics.

CLAIRAMBAULT & RIBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 10 / 10