Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Launchbury's Natural Semantics for Lazy Evaluation

Launchbury's Natural Semantics for Lazy Evaluation

Talk at fp-syd September 2010. See also the code at https://bitbucket.org/inkytonik/natural-lazy

Tony Sloane

August 21, 2014
Tweet

More Decks by Tony Sloane

Other Decks in Programming

Transcript

  1. Anthony M. Sloane Programming Languages Research Group Department of Computing,

    Macquarie University Sydney, Australia http://www.comp.mq.edu.au/~asloane http://plrg.science.mq.edu.au Launchbury's Natural Semantics for Lazy Evaluation Thursday, 16 September 2010
  2. A Natural Semantics for Lazy Evaluation John Launchbury In POPL

    ’93: Proceedings of the 20th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (New York, NY, USA, 1993), ACM, pp. 144–154. Aims to capture both non-strictness of evaluation and sharing of certain reductions. Achieves a middle ground between more abstract semantic descriptions and the detailed operational semantics of abstract machines. Thursday, 16 September 2010
  3. let u = 3 + 2, v = u +

    1 in v + v let u = 3 + 2, f = λx.(let v = u + 1 in v + x) in f 2 + f 3 let u = 3 + 2, f = (let v = u + 1 in λx.v + x) in f 2 + f 3 Examples Thursday, 16 September 2010
  4. Lambda calculus with recursive lets. Source language x ∈ Var

    e ∈ Exp ::= λx.e | e e | x | let x1 = e1, . . . , xn = en in e Thursday, 16 September 2010
  5. Unique bound variable names and applications only to variables. Normalised

    language x ∈ Var e ∈ Exp ::= λx.e | e x | x | let x1 = e1, . . . , xn = en in e e x → e x e1 e2 → let y = e2 in e1 y (where y is a fresh variable) Thursday, 16 September 2010
  6. Naming conventions Reduction evaluating an expression in the context of

    a starting heap gives a value and a new heap Judgement Γ, ∆, Θ ∈ Heap = Var → Exp z ∈ Val ::= λx.e Γ : e ⇓ ∆ : z Thursday, 16 September 2010
  7. Γ : λx.e ⇓ Γ : λx.e Γ : e

    ⇓ ∆ : λy.e￿ ∆ : e￿[x/y] ⇓ Θ : z Γ : e x ⇓ Θ : z Γ : e ⇓ Θ : z (Γ, x ￿→ e) : x ⇓ (Θ, x ￿→ z) : ˆ z (Γ, x1 ￿→ e1, . . . , xn ￿→ en) : e ⇓ ∆ : z Γ : let x1 = e1, . . . , xn = en in e ⇓ ∆ : z ˆ z Reduction rules (lambda) (app) (var) (let) means rename the bound variables in the value to be fresh Thursday, 16 September 2010
  8. Arithmetic primitives are strict. Numbers n ∈ Number ⊕ ∈

    Primitive e ∈ Exp ::= n | e1 ⊕ e2 Γ : n ⇓ Γ : n Γ : e1 ⇓ ∆ : n1 ∆ : e2 ⇓ Θ : n2 Γ : e1 ⊕ e2 ⇓ Θ : n1 ⊕ n2 Thursday, 16 September 2010
  9. Constructors and constants Case selection is strict. c ∈ Constructor

    e ∈ Exp ::= c x1 . . . xn | case e of {ci y1 . . . ymi → ei }n i=1 Γ : c x1 . . . xn ⇓ Γ : c x1 . . . xn Γ : e ⇓ ∆ : ck x1 . . . xmk ∆ : ek[xi/yi]mk i=1 ⇓ Θ : z Γ : case e of {ci y1 . . . ymi → ei }n i=1 ⇓ Θ : z Thursday, 16 September 2010
  10. Other extensions and applications Garbage collection augment judgement with set

    of "active" names add rule to remove non-"reachable" bindings from heap Cost counting augment judgement with reduction counter Verification use semantics to prove correctness of transformations Thursday, 16 September 2010
  11. Downloads These slides and a Scala implementation of the semantics

    can be downloaded from: http://code.google.com/p/kiama/wiki/Research Thursday, 16 September 2010