cse 505 programming languages lecture 12 safely extending
play

CSE 505: Programming Languages Lecture 12 Safely Extending STLC: - PowerPoint PPT Presentation

CSE 505: Programming Languages Lecture 12 Safely Extending STLC: Progress, Preservation, Lets, Branches Zach Tatlock Fall 2013 Review e ::= x. e | x | e e | c ::= int | v ::= x. e | c ::= | , x : e 1


  1. CSE 505: Programming Languages Lecture 12 — Safely Extending STLC: Progress, Preservation, Lets, Branches Zach Tatlock Fall 2013

  2. Review e ::= λx. e | x | e e | c τ ::= int | τ → τ v ::= λx. e | c Γ ::= · | Γ , x : τ e 1 → e ′ e 2 → e ′ 1 2 ( λx. e ) v → e [ v/x ] e 1 e 2 → e ′ 1 e 2 v e 2 → v e ′ 2 e [ e ′ /x ] : capture-avoiding substitution of e ′ for free x in e Γ , x : τ 1 ⊢ e : τ 2 Γ ⊢ c : int Γ ⊢ x : Γ( x ) Γ ⊢ λx. e : τ 1 → τ 2 Γ ⊢ e 1 : τ 2 → τ 1 Γ ⊢ e 2 : τ 2 Γ ⊢ e 1 e 2 : τ 1 Preservation: If · ⊢ e : τ and e → e ′ , then · ⊢ e ′ : τ . Progress: If · ⊢ e : τ , then e is a value or ∃ e ′ such that e → e ′ . Zach Tatlock CSE 505 Fall 2013, Lecture 12 2

  3. Adding Stuff Time to use STLC as a foundation for understanding other common language constructs We will add things via a principled methodology thanks to a proper education ◮ Extend the syntax ◮ Extend the operational semantics ◮ Derived forms (syntactic sugar), or ◮ Direct semantics ◮ Extend the type system ◮ Extend soundness proof (new stuck states, proof cases) In fact, extensions that add new types have even more structure Zach Tatlock CSE 505 Fall 2013, Lecture 12 3

  4. Let bindings (CBV) e ::= . . . | let x = e 1 in e 2 e 1 → e ′ 1 let x = e 1 in e 2 → let x = e ′ 1 in e 2 let x = v in e → e [ v/x ] Γ , x : τ ′ ⊢ e 2 : τ Γ ⊢ e 1 : τ ′ Γ ⊢ let x = e 1 in e 2 : τ (Also need to extend definition of substitution...) Progress: If e is a let, 1 of the 2 new rules apply (using induction) Preservation: Uses Substitution Lemma Substitution Lemma: Uses Weakening and Exchange Zach Tatlock CSE 505 Fall 2013, Lecture 12 4

  5. Derived forms let seems just like λ , so can make it a derived form ◮ let x = e 1 in e 2 “a macro” / “desugars to” ( λx. e 2 ) e 1 ◮ A “derived form” (Harder if λ needs explicit type) Or just define the semantics to replace let with λ : let x = e 1 in e 2 → ( λx. e 2 ) e 1 These 3 semantics are different in the state-sequence sense ( e 1 → e 2 → . . . → e n ) ◮ But (totally) equivalent and you could prove it (not hard) Note: ML type-checks let and λ differently (later topic) Note: Don’t desugar early if it hurts error messages! Zach Tatlock CSE 505 Fall 2013, Lecture 12 5

  6. Booleans and Conditionals e ::= . . . | true | false | if e 1 e 2 e 3 v ::= . . . | true | false τ ::= . . . | bool e 1 → e ′ 1 if e 1 e 2 e 3 → if e ′ 1 e 2 e 3 if true e 2 e 3 → e 2 if false e 2 e 3 → e 3 Γ ⊢ e 1 : bool Γ ⊢ e 2 : τ Γ ⊢ e 3 : τ Γ ⊢ if e 1 e 2 e 3 : τ Γ ⊢ true : bool Γ ⊢ false : bool Also extend definition of substitution (will stop writing that)... Notes: CBN, new Canonical Forms case, all lemma cases easy Zach Tatlock CSE 505 Fall 2013, Lecture 12 6

Recommend


More recommend