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 (based on simple examples) C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 2 / 10
Naive Introduction The First Example Consider the programs bar(f:int->int): foo(f:int->int): a = f(5) and return f(5) + f(5) return a + a C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10
Naive Introduction The First Example Consider the programs bar(f:int->int): foo(f:int->int): a = f(5) and return f(5) + f(5) return a + a Are these two programs equivalent ? C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10
Naive Introduction The First Example Consider the programs bar(f:int->int): foo(f:int->int): a = f(5) and return f(5) + f(5) return a + a Are these two programs equivalent ? ◮ They are not equivalent if f can access a global reference. C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10
Naive Introduction The First Example Consider the programs bar(f:int->int): foo(f:int->int): a = f(5) and return f(5) + 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 . C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10
Naive Introduction The First Example Consider the programs bar(f:int->int): foo(f:int->int): a = f(5) and return f(5) + 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). C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10
Naive Introduction The First Example Consider the programs bar(f:int->int): foo(f:int->int): a = f(5) and return f(5) + 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. C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10
Naive Introduction The First Example Consider the programs bar(f:int->int): foo(f:int->int): a = f(5) and return f(5) + 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. C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 3 / 10
Naive Introduction Types as Sets ◮ Assume types, say int , bool , are to be interpreted as sets � int � , � bool � . C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10
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) C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10
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 C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10
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 � C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10
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 � ) C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 4 / 10
Naive Introduction A Taste of Finitary PCF Motivation. ◮ A simple language to discuss � bool � := {⊥ , true , false } C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 5 / 10
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 | | | if t then u else v | Ω true false C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 5 / 10
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 | | | if t then u else v | Ω true false ◮ Purely functional language with Booleans and divergence ( Ω ). C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 5 / 10
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 | | | if t then u else v | Ω true false ◮ 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 C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 5 / 10
Naive Introduction Example. Consider the two following or programs: or_l := fun a, b -> or_r := fun a, b -> vs if a then a else b if b then b else a C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 6 / 10
Naive Introduction Example. Consider the two following or programs: or_l := fun a, b -> or_r := fun a, b -> vs if a then a else 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 ? C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 6 / 10
Naive Introduction Example. Consider the two following or programs: or_l := fun a, b -> or_r := fun a, b -> vs if a then a else 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 C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 6 / 10
Naive Introduction Example. Consider the two following or programs: or_l := fun a, b -> or_r := fun a, b -> vs if a then a else 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 ? C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 6 / 10
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). C LAIRAMBAULT & R IBA (LIP - ENS de Lyon) ASPL (CR04) Course 01 09/11 7 / 10
Recommend
More recommend