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

a universe of binding and computation
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

A Universe of Binding and Computation

1

Dan Licata and Robert Harper

Carnegie Mellon University

1

slide-2
SLIDE 2

2

Goal

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

2

slide-3
SLIDE 3

2

Goal

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

2

slide-4
SLIDE 4

3

Binding

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

3

slide-5
SLIDE 5

3

Binding

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

3

slide-6
SLIDE 6

3

Binding

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

weak function space representing binding: means “an exp in the presence of a new exp”

3

slide-7
SLIDE 7

4

Computation

normalize : exp ⊃ exp normalize (lam x.e) = ... normalize (app e1 e2) = …

pattern-matching recursive function

4

slide-8
SLIDE 8

5

Our Approach

5

slide-9
SLIDE 9

5

Our Approach

  • 1. Makes an a priori type distinction between

⇒ (binding) and ⊃ (computation) [unlike Parametric & Weak HOAS / Hybrid ]

5

slide-10
SLIDE 10

5

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

slide-11
SLIDE 11

5

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

slide-12
SLIDE 12

6

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

slide-13
SLIDE 13

6

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

slide-14
SLIDE 14

7

Contextual Types

Contextual types <Ψ> A track scoping of variables: E.g. < x1 : exp … xn : exp > exp

free vars in x1 … xn

{

7

slide-15
SLIDE 15

7

Contextual Types

Contextual types <Ψ> A track scoping of variables: E.g. < x1 : exp … xn : exp > exp normalize : <⋅>exp ⊃ <⋅>exp normalize/open : ∀ Ψ. <Ψ>exp ⊃ <Ψ>exp Permit precise types for computations:

free vars in x1 … xn

{

7

slide-16
SLIDE 16

8

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

slide-17
SLIDE 17

9

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

slide-18
SLIDE 18

10

Universe

Datatype of codes naming a user-defined collection

  • f types

data Code where … Interpretation function maps codes to Agda Sets: Elements : Code → Set Ingredients:

10

slide-19
SLIDE 19

10

Universe

Datatype of codes naming a user-defined collection

  • f types

data Code where … Interpretation function maps codes to Agda Sets: Elements : Code → Set Ingredients: This work: universe of contextual types

10

slide-20
SLIDE 20

11

Contextual Universe

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

11

slide-21
SLIDE 21

12

Interpretation

<Ψ> (A list) = List <Ψ>A <Ψ> (A ⊃ B) = <Ψ>A → <Ψ>B <Ψ> (Ψ’ ⇒ A) = <Ψ,Ψ’>A <Ψ> (∀ Ψ’. A) = (Ψ’ : Ctx) → <Ψ>(A Ψ’) <Ψ> D = …

Context Code for a Contextual Type Agda Set

12

slide-22
SLIDE 22

13

Interpretation

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

13

slide-23
SLIDE 23

14

Pronominal Variables

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

14

slide-24
SLIDE 24

15

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

slide-25
SLIDE 25

16

Scope-correct NBE

Normalize syntactic λ-terms by interpreting them as computational functions ⊃ in the metalanguage

16

slide-26
SLIDE 26

16

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

slide-27
SLIDE 27

16

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)

maps closed expressions to closed expressions

16

slide-28
SLIDE 28

17

Semantics

17

slide-29
SLIDE 29

17

Semantics

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

17

slide-30
SLIDE 30

17

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

slide-31
SLIDE 31

17

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

slide-32
SLIDE 32

18

napp : neu ⇒ sem ⇒ neu neut : neu ⇒ sem slam : (sem ⊃ sem) ⇒ sem

Semantics

Semantic S ::= slam φ | neut(R) Neutral R ::= x | napp(R,S)

sem ⊃ sem

18

slide-33
SLIDE 33

18

napp : neu ⇒ sem ⇒ neu neut : neu ⇒ sem slam : (sem ⊃ sem) ⇒ sem

Semantics

Semantic S ::= slam φ | neut(R) Neutral R ::= x | napp(R,S)

sem ⊃ sem however, it’s not enough that φ works in the current context Ψ

18

slide-34
SLIDE 34

19

napp : neu ⇒ sem ⇒ neu neut : neu ⇒ sem slam : (∀ Ψ. Ψ ⇒ (sem ⊃ sem)) ⇒ sem

Semantics

semantic function that anticipates extensions of the context sem ⊃ sem

Semantic S ::= slam φ | neut(R) Neutral R ::= x | napp(R,S)

19

slide-35
SLIDE 35

19

napp : neu ⇒ sem ⇒ neu neut : neu ⇒ sem slam : (∀ Ψ. Ψ ⇒ (sem ⊃ sem)) ⇒ sem

Semantics

semantic function that anticipates extensions of the context sem ⊃ sem

Semantic S ::= slam φ | neut(R) Neutral R ::= x | napp(R,S)

19

slide-36
SLIDE 36

20

eval: <⋅> (exp ⊃ sem)

20

slide-37
SLIDE 37

21

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

21

slide-38
SLIDE 38

21

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

<Ψ> ([Ψ’] A) = <Ψ’> A

21

slide-39
SLIDE 39

21

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

<Ψ> ([Ψ’] A) = <Ψ’> A

env Ψe Ψs = [Ψe](exp#) ⊃ [Ψs]sem Environment type:

21

slide-40
SLIDE 40

21

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

<Ψ> ([Ψ’] A) = <Ψ’> A

env Ψe Ψs = [Ψe](exp#) ⊃ [Ψs]sem

<Ψ> (D#) = D ∈ Ψ

Environment type:

21

slide-41
SLIDE 41

22

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

22

slide-42
SLIDE 42

23

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

23

slide-43
SLIDE 43

24

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

24

slide-44
SLIDE 44

25

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

25

slide-45
SLIDE 45

26

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’ eval: <⋅> ∀ Ψe, Ψs. env Ψe Ψs ⊃ [Ψe]exp ⊃ [Ψs]sem

26

slide-46
SLIDE 46

27

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’ eval: <⋅> ∀ Ψe, Ψs. env Ψe Ψs ⊃ [Ψe]exp ⊃ [Ψs]sem

27

slide-47
SLIDE 47

28

σ’ (iS x) = weaken (σ x) with Ψs’

28

slide-48
SLIDE 48

28

σ’ (iS x) = weaken (σ x) with Ψs’

has type <Ψs>sem

28

slide-49
SLIDE 49

28

σ’ (iS x) = weaken (σ x) with Ψs’

weaken : <Ψs> sem ⊃ (Ψs’ ⇒ sem) has type <Ψs>sem

28

slide-50
SLIDE 50

28

σ’ (iS x) = weaken (σ x) with Ψs’

weaken : <Ψs> sem ⊃ (Ψs’ ⇒ sem) has type <Ψs>sem

In raw Agda, would need to implement for each

  • bject language…

28

slide-51
SLIDE 51

29

This Paper

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

29

slide-52
SLIDE 52

30

Structural Properties

Weakening: ∀Ψ. Ψ ⇒ (A ⊃ (D ⇒ A)) Substitution: ∀Ψ. Ψ ⇒ (D ⇒ A) ⊃ (D ⊃ A) Exchange: ∀Ψ. Ψ ⇒(D1 ⇒ D2 ⇒ A) ⊃ (D2 ⇒ D1 ⇒ A) Contraction: ∀Ψ. Ψ ⇒(D ⇒ D ⇒ A) ⊃ (D ⇒ A) Strengthening: ∀Ψ. Ψ ⇒(D ⇒ A) ⊃ A

30

slide-53
SLIDE 53

31

Structural Properties

In mixed, pronominal setting, structural properties do not hold at all types: Computational functions express side conditions on the current context (Ψ ⊢ J) ⊃ 0 Ψ ⊢ J’

31

slide-54
SLIDE 54

31

Structural Properties

In mixed, pronominal setting, structural properties do not hold at all types: Computational functions express side conditions on the current context (Ψ ⊢ J) ⊃ 0 Ψ ⊢ J’

“it is not the case that Ψ ⊢ J” Proof cannot be weakened with J because Ψ,J ⊢ J

31

slide-55
SLIDE 55

31

Structural Properties

In mixed, pronominal setting, structural properties do not hold at all types: Computational functions express side conditions on the current context (Ψ ⊢ J) ⊃ 0 Ψ ⊢ J’

“it is not the case that Ψ ⊢ J” Proof cannot be weakened with J because Ψ,J ⊢ J

But there are sufficient conditions under which they do hold…

31

slide-56
SLIDE 56

32

Structural Properties

Instances of weakening:

32

slide-57
SLIDE 57

32

Structural Properties

exp ⊃ (exp ⇒ exp) Instances of weakening:

32

slide-58
SLIDE 58

32

Structural Properties

exp ⊃ (exp ⇒ exp) Instances of weakening:

OK

32

slide-59
SLIDE 59

32

Structural Properties

exp ⊃ (exp ⇒ exp) (exp ⇒ exp) ⊃ (exp ⇒ (exp ⇒ exp)) Instances of weakening:

OK

32

slide-60
SLIDE 60

32

Structural Properties

exp ⊃ (exp ⇒ exp) (exp ⇒ exp) ⊃ (exp ⇒ (exp ⇒ exp)) Instances of weakening:

OK OK

32

slide-61
SLIDE 61

32

Structural Properties

exp ⊃ (exp ⇒ exp) (exp ⇒ exp) ⊃ (exp ⇒ (exp ⇒ exp)) (exp ⊃ exp) ⊃ (exp ⇒ (exp ⊃ exp)) Instances of weakening:

OK OK

32

slide-62
SLIDE 62

32

Structural Properties

exp ⊃ (exp ⇒ exp) (exp ⇒ exp) ⊃ (exp ⇒ (exp ⇒ exp)) (exp ⊃ exp) ⊃ (exp ⇒ (exp ⊃ exp)) Instances of weakening:

OK OK ?

32

slide-63
SLIDE 63

33

Structural Properties

Weakening: (exp ⊃ exp) ⊃ (exp ⇒ (exp ⊃ exp)) Given, for example, normalize : <⋅> (exp ⊃ exp) normalize (lam x.e) = … normalize (app e1 e2) = … normalize (var x) = impossible

33

slide-64
SLIDE 64

34

Structural Properties

Weakening: (exp ⊃ exp) ⊃ (exp ⇒ (exp ⊃ exp)) Must create normalize’ : <⋅> (exp ⇒ (exp ⊃ exp)) normalize’ y.(lam x.e) = … normalize’ y.(app e1 e2) = … normalize’ y.(var y) = ???

34

slide-65
SLIDE 65

35

Structural Properties

Structural properties are not built-in (unlike LF): OK that they only hold at certain types Implemented datatype-generically but conditionally: “free” when conditions hold Conditions discharged automatically weaken: A ⊃ (D ⇒ A) if canWkn(D,A)

possible when D does not appear to the left of an ⊃ in A

35

slide-66
SLIDE 66

36

Conclusion

Implemented a framework for mixing binding and computation in a pronominal setting Datatype-generic implementations of the structural properties by recursion over universe See paper for more examples and comparisons with Twelf/Delphin/Beluga/FreshML

36

slide-67
SLIDE 67

37

Future Work

Positivity check for signature + termination Equational behavior of structural properties Named syntax for variables; More-convenient syntax for structural properties Derived induction principles for structural props Dependent types!

37

slide-68
SLIDE 68

Thanks for listening!

38