a universe of binding and computation
play

A Universe of Binding and Computation Dan Licata and Robert Harper - PowerPoint PPT Presentation

A Universe of Binding and Computation Dan Licata and Robert Harper Carnegie Mellon University 1 1 Goal Functional programming with binding and scope Applications: Domain-specific logics for reasoning about code Mechanized metatheory 2 2


  1. A Universe of Binding and Computation Dan Licata and Robert Harper Carnegie Mellon University 1 1

  2. Goal Functional programming with binding and scope Applications: Domain-specific logics for reasoning about code Mechanized metatheory 2 2

  3. Goal Functional programming with binding and scope Applications: Domain-specific logics for reasoning about code Mechanized metatheory Two important ingredients... 2 2

  4. Binding Represent bound variables: lam(x.e) , ∀ x: τ .A , hypothetical judgements 3 3

  5. Binding Represent bound variables: lam(x.e) , ∀ x: τ .A , hypothetical judgements E.g. type exp representing syntax of λ -terms: app : exp ⇒ exp ⇒ exp lam : (exp ⇒ exp) ⇒ exp 3 3

  6. Binding Represent bound variables: lam(x.e) , ∀ x: τ .A , hypothetical judgements E.g. type exp representing syntax of λ -terms: app : exp ⇒ exp ⇒ exp lam : (exp ⇒ exp) ⇒ exp weak function space representing binding: means “an exp in the presence of a new exp” 3 3

  7. Computation pattern-matching recursive function normalize : exp ⊃ exp normalize (lam x.e) = ... normalize (app e1 e2) = … 4 4

  8. Our Approach 5 5

  9. Our Approach 1. Makes an a priori type distinction between ⇒ (binding) and ⊃ (computation) [unlike Parametric & Weak HOAS / Hybrid ] 5 5

  10. Our Approach 1. Makes an a priori type distinction between ⇒ (binding) and ⊃ (computation) [unlike Parametric & Weak HOAS / Hybrid ] 2. As two types in the same language [unlike Twelf/Delphin/Beluga] 5 5

  11. Our Approach 1. Makes an a priori type distinction between ⇒ (binding) and ⊃ (computation) [unlike Parametric & Weak HOAS / Hybrid ] 2. As two types in the same language [unlike Twelf/Delphin/Beluga] 3. Treats variables pronominally [unlike nominal logic / FreshML / c α ml] 5 5

  12. Pronominal Variables Treat variables as pronouns , not nouns: reference to a designated binding site y : exp , z : exp ⊢ lam (x.app(z , x)) : exp 6 6

  13. Pronominal Variables Treat variables as pronouns , not nouns: reference to a designated binding site y : exp , z : exp ⊢ lam (x.app(z , x)) : exp Can test equality of variables as pointers, not as names 6 6

  14. Contextual Types Contextual types < Ψ > A track scoping of variables: E.g. < x 1 : exp … x n : exp > exp { free vars in x 1 … x n 7 7

  15. Contextual Types Contextual types < Ψ > A track scoping of variables: E.g. < x 1 : exp … x n : exp > exp { free vars in x 1 … x n Permit precise types for computations: normalize : < ⋅ >exp ⊃ < ⋅ >exp normalize/open : ∀ Ψ . < Ψ >exp ⊃ < Ψ >exp 7 7

  16. This Paper Implement a framework as a universe in Agda Examples and comparisons with Twelf/Delphin/Beluga/FreshML Datatype-generic implementations of the structural properties 8 8

  17. This Paper Implement framework as a universe in Agda Examples and comparisons with Twelf/Delphin/Beluga/FreshML Datatype-generic implementations of the structural properties 9 9

  18. Universe Ingredients: Datatype of codes naming a user-defined collection of types data Code where … Interpretation function maps codes to Agda Sets: Elements : Code → Set 10 10

  19. Universe Ingredients: Datatype of codes naming a user-defined collection of types data Code where … Interpretation function maps codes to Agda Sets: Elements : Code → Set This work: universe of contextual types 10 10

  20. Contextual Universe Datatype of codes for contextual types: data Ctx Ψ ::= ⋅ | Ψ , D data Code A ::= A list | A ⊃ B | D | Ψ ⇒ A | ∀ Ψ . A Interpretation < Ψ >A: <_>_ : Ctx → Code → Set 11 11

  21. Interpretation Code for a Context Agda Set Contextual Type < Ψ > (A list) = List < Ψ >A < Ψ > (A ⊃ B) = < Ψ >A → < Ψ >B < Ψ > ( Ψ ’ ⇒ A) = < Ψ , Ψ ’>A < Ψ > ( ∀ Ψ ’. A) = ( Ψ ’ : Ctx) → < Ψ >(A Ψ ’) < Ψ > D = … 12 12

  22. Interpretation app : (exp * exp) ⇒ exp lam : (exp ⇒ exp) ⇒ exp < Ψ > exp = Expr Ψ where data Expr : Ctx → Set where lam : < Ψ >(exp ⇒ exp) → Expr Ψ app : < Ψ >(exp * exp) → Expr Ψ var : (exp ∈ Ψ ) → Expr Ψ 13 13

  23. Pronominal Variables var : (exp ∈ Ψ ) → Expr Ψ data _ ∈ _ : Datatype → Ctx → Set where i0 : D ∈ ( Ψ , D) iS : (D ∈ Ψ ) → D ∈ ( Ψ , D’) 14 14

  24. This Paper Implement framework as a universe in Agda Examples and comparisons with Twelf/Delphin/ Beluga/FreshML Datatype-generic implementations of the structural properties 15 15

  25. Scope-correct NBE Normalize syntactic λ -terms by interpreting them as computational functions ⊃ in the metalanguage 16 16

  26. Scope-correct NBE Normalize syntactic λ -terms by interpreting them as computational functions ⊃ in the metalanguage norm : < ⋅ > (exp ⊃ exp) norm e = reify (eval e) where eval : < ⋅ > (exp ⊃ sem) reify : < ⋅ > (sem ⊃ exp) 16 16

  27. Scope-correct NBE Normalize syntactic λ -terms by interpreting them as computational functions ⊃ in the metalanguage maps closed expressions to closed expressions norm : < ⋅ > (exp ⊃ exp) norm e = reify (eval e) where eval : < ⋅ > (exp ⊃ sem) reify : < ⋅ > (sem ⊃ exp) 16 16

  28. Semantics 17 17

  29. Semantics First cut: sem = μ s. s ⊃ s eval : < ⋅ > exp ⊃ sem eval (app e1 e2) = (unroll (eval e1)) (eval e2) 17 17

  30. Semantics First cut: sem = μ s. s ⊃ s eval : < ⋅ > exp ⊃ sem eval (app e1 e2) = (unroll (eval e1)) (eval e2) But how do you write reify : < ⋅ > sem ⊃ exp ? 17 17

  31. Semantics First cut: sem = μ s. s ⊃ s eval : < ⋅ > exp ⊃ sem eval (app e1 e2) = (unroll (eval e1)) (eval e2) But how do you write reify : < ⋅ > sem ⊃ exp ? Requires a slightly different target type... 17 17

  32. Semantics sem ⊃ sem Semantic S ::= slam φ | neut(R) Neutral R ::= x | napp(R,S) napp : neu ⇒ sem ⇒ neu neut : neu ⇒ sem slam : (sem ⊃ sem) ⇒ sem 18 18

  33. Semantics sem ⊃ sem Semantic S ::= slam φ | neut(R) Neutral R ::= x | napp(R,S) napp : neu ⇒ sem ⇒ neu neut : neu ⇒ sem slam : (sem ⊃ sem) ⇒ sem however, it’s not enough that φ works in the current context Ψ 18 18

  34. Semantics sem ⊃ sem Semantic S ::= slam φ | neut(R) Neutral R ::= x | napp(R,S) napp : neu ⇒ sem ⇒ neu neut : neu ⇒ sem slam : ( ∀ Ψ . Ψ ⇒ (sem ⊃ sem)) ⇒ sem semantic function that anticipates extensions of the context 19 19

  35. Semantics sem ⊃ sem Semantic S ::= slam φ | neut(R) Neutral R ::= x | napp(R,S) napp : neu ⇒ sem ⇒ neu neut : neu ⇒ sem slam : ( ∀ Ψ . Ψ ⇒ (sem ⊃ sem)) ⇒ sem semantic function that anticipates extensions of the context 19 19

  36. eval: < ⋅ > (exp ⊃ sem) 20 20

  37. eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem 21 21

  38. < Ψ > ([ Ψ ’] A) = < Ψ ’> A eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem 21 21

  39. < Ψ > ([ Ψ ’] A) = < Ψ ’> A eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem Environment type: env Ψ e Ψ s = [ Ψ e ](exp#) ⊃ [ Ψ s ]sem 21 21

  40. < Ψ > ([ Ψ ’] A) = < Ψ ’> A eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem Environment type: env Ψ e Ψ s = [ Ψ e ](exp#) ⊃ [ Ψ s ]sem < Ψ > (D#) = D ∈ Ψ 21 21

  41. eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem eval σ (var x) = σ x eval σ (app e1 e2) = appsem (eval σ e1) (eval σ e2) eval σ (lam e) = ? 22 22

  42. eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem eval{ Ψ e }{ Ψ s } σ (lam e) = slam φ 23 23

  43. eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem eval{ Ψ e }{ Ψ s } σ (lam e) = slam φ where φ : < Ψ s > ∀ Ψ s ’. Ψ s ’ ⇒ (sem ⊃ sem) φ = ? 24 24

  44. eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem eval{ Ψ e }{ Ψ s } σ (lam e) = slam φ where φ : < Ψ s > ∀ Ψ s ’. Ψ s ’ ⇒ (sem ⊃ sem) φ Ψ s ’ s’ = eval{ Ψ e , exp}{ Ψ s , Ψ s ’} σ ’ e 25 25

  45. eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem eval{ Ψ e }{ Ψ s } σ (lam e) = slam φ where φ : < Ψ s > ∀ Ψ s ’. Ψ s ’ ⇒ (sem ⊃ sem) φ Ψ s ’ s’ = eval{ Ψ e , exp}{ Ψ s , Ψ s ’} σ ’ e where σ ’ : ([ Ψ e , exp]exp# ⊃ [ Ψ s , Ψ s ’]sem σ ’ = extend σ with s’ 26 26

  46. eval: < ⋅ > ∀ Ψ e , Ψ s . env Ψ e Ψ s ⊃ [ Ψ e ]exp ⊃ [ Ψ s ]sem eval{ Ψ e }{ Ψ s } σ (lam e) = slam φ where φ : < Ψ s > ∀ Ψ s ’. Ψ s ’ ⇒ (sem ⊃ sem) φ Ψ s ’ s’ = eval{ Ψ e , exp}{ Ψ s , Ψ s ’} σ ’ e where σ ’ : ([ Ψ e , exp]exp# ⊃ [ Ψ s , Ψ s ’]sem σ ’ i0 = s’ σ ’ (iS x) = weaken ( σ x) with Ψ s ’ 27 27

  47. σ ’ (iS x) = weaken ( σ x) with Ψ s ’ 28 28

  48. has type < Ψ s >sem σ ’ (iS x) = weaken ( σ x) with Ψ s ’ 28 28

Recommend


More recommend