vrijeuniversiteitamsterdammiddlesexuniversitylondonethzüri...

61
Bindings as Bounded Natural Functors Jasmin Blanchette, Lorenzo Gheri, Andrei Popescu, Dmitriy Traytel λ = Isabelle β α Vrije Universiteit Amsterdam Middlesex University London ETH Zürich

Upload: others

Post on 05-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Bindings as Bounded Natural Functors

Jasmin Blanchette, Lorenzo Gheri, Andrei Popescu, Dmitriy Traytel

λ→

∀=Is

abelle

β

α

Vrije Universiteit Amsterdam Middlesex University London ETH Zürich

Page 2: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Bindings as Bounded Natural Functors

Jasmin Blanchette, Lorenzo Gheri, Andrei Popescu, Dmitriy Traytel

Vrije Universiteit Amsterdam Middlesex University London ETH Zürich

https://www.youtube.com/watch?v=gkq2ONqQ2MI

Page 3: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Our Contribution

Modular framework for datatypes with bindings- Complex variable binders- Infinitary syntax too (including coinductive datatypes)

Formalized in the Isabelle/HOL proof assistant

It is being implemented as a definitional package λ→

∀=Is

abelle

β

α

Page 4: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

What is a Binder?

Several very expressive syntactic formats:CαMl [Pottier 2006]Ott [Sewell et al. 2010]Unbound [Weirich et al. 2011]Isabelle Nominal2 [Urban and Kaliszyk 2012]Needle&Knot [Keuchel et al. 2016]

Proposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Think: F (V1, . . . ,Vm,T1, . . . ,Tn) combines variables vi ∈ Vi andterms tj ∈ Tj such that vi ∈ Vi binds in tj ∈ Tj if (i , j) ∈ θ.

λv . t

m = n = 1F (V ,T ) = V × Tθ = {(1, 1)}

let v = t1 in t2

m = 1, n = 2F (V ,T1,T2) = V × T1 × T2θ = {(1, 2)}

let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Page 5: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

What is a Binder?Several very expressive syntactic formats:

CαMl [Pottier 2006]Ott [Sewell et al. 2010]Unbound [Weirich et al. 2011]Isabelle Nominal2 [Urban and Kaliszyk 2012]Needle&Knot [Keuchel et al. 2016]

Proposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Think: F (V1, . . . ,Vm,T1, . . . ,Tn) combines variables vi ∈ Vi andterms tj ∈ Tj such that vi ∈ Vi binds in tj ∈ Tj if (i , j) ∈ θ.

λv . t

m = n = 1F (V ,T ) = V × Tθ = {(1, 1)}

let v = t1 in t2

m = 1, n = 2F (V ,T1,T2) = V × T1 × T2θ = {(1, 2)}

let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Page 6: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

What is a Binder?Binder = Mechanism for combining any variables with any terms.

Proposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Think: F (V1, . . . ,Vm,T1, . . . ,Tn) combines variables vi ∈ Vi andterms tj ∈ Tj such that vi ∈ Vi binds in tj ∈ Tj if (i , j) ∈ θ.

λv . t

m = n = 1F (V ,T ) = V × Tθ = {(1, 1)}

let v = t1 in t2

m = 1, n = 2F (V ,T1,T2) = V × T1 × T2θ = {(1, 2)}

let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Page 7: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

What is a Binder?Binder = Mechanism for combining any variables with any terms.

Proposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Think: F (V1, . . . ,Vm,T1, . . . ,Tn) combines variables vi ∈ Vi andterms tj ∈ Tj such that vi ∈ Vi binds in tj ∈ Tj if (i , j) ∈ θ.

λv . t

m = n = 1F (V ,T ) = V × Tθ = {(1, 1)}

let v = t1 in t2

m = 1, n = 2F (V ,T1,T2) = V × T1 × T2θ = {(1, 2)}

let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Page 8: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

What is a Binder?Binder = Mechanism for combining any variables with any terms.

Proposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Think: F (V1, . . . ,Vm,T1, . . . ,Tn) combines variables vi ∈ Vi andterms tj ∈ Tj such that vi ∈ Vi binds in tj ∈ Tj if (i , j) ∈ θ.

λv . tm = n = 1F (V ,T ) = V × Tθ = {(1, 1)}

let v = t1 in t2

m = 1, n = 2F (V ,T1,T2) = V × T1 × T2θ = {(1, 2)}

let rec v1 = t1 and . . . and vk = tk in tm = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Page 9: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Finitary?

F “Natural” (Container-like)

Functor?

let rec (v = t)∗ in tF (V ,T ) =List (V × T )× Tblθ = {(1, 1)}

let rec v = t1 and v = t2 in t

[(v , t1), (v , t2)] ∈ List (V × T )

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}

←−−

{v , . . .}

Page 10: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Finitary?

F “Natural” (Container-like)

Functor?

let rec (v = t)∗ in tF (V ,T ) =List (V × T )× Tblθ = {(1, 1)}

let rec v = t1 and v = t2 in t

[(v , t1), (v , t2)] ∈ List (V × T )

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 11: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Finitary?F “Natural” (Container-like)

Functor?

let rec (v = t)∗ in tF (V ,T ) =List (V × T )× Tblθ = {(1, 1)}

let rec v = t1 and v = t2 in t

[(v , t1), (v , t2)] ∈ List (V × T )

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 12: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

BoundedF “Natural” (Container-like)

Functor?

let rec (v = t)∗ in tF (V ,T ) =List (V × T )× Tblθ = {(1, 1)}

let rec v = t1 and v = t2 in t

[(v , t1), (v , t2)] ∈ List (V × T )

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 13: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

BoundedF “Natural” (Container-like)

Functor?

let rec (v = t)∗ in tF (V ,T ) =List (V × T )× Tblθ = {(1, 1)}

let rec v = t1 and v = t2 in t

[(v , t1), (v , t2)] ∈ List (V × T )

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 14: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

BoundedF “Natural” (Container-like)

Functor?

let rec (v = t)∗ in tF (V ,T ) =List (V × T )× Tblθ = {(1, 1)}

let rec v = t1 and v = t2 in t

[(v , t1), (v , t2)] ∈ List (V × T )

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 15: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

BoundedF “Natural” (Container-like)

Functor?

let rec (v = t)∗ in tF (V ,T ) =List (V × T )@V × Tθ = {(1, 1)}

let rec v = t1 and v = t2 in t

[(v , t1), (v , t2)] ∈ List (V × T )

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 16: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

BoundedF “Natural” (Container-like)

Functor on (binding) variable arguments only w.r.t. injections

let rec (v = t)∗ in tF (V ,T ) =List (V × T )@V × Tθ = {(1, 1)}

let rec v = t1 and v = t2 in t

[(v , t1), (v , t2)] ∈ List (V × T )

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 17: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

BoundedF “Natural” (Container-like)

Functor on (binding) variable arguments only w.r.t. injections

w (v). p

p = m = n = 1F (W ,V ,T ) = W × V × Tθ = {(1, 1)}

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w

v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 18: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of BindersProposal: Binder = Operator on sets F : Setp × Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

BoundedF “Natural” (Container-like)

Functor on (binding) variable arguments only w.r.t. injections

w (v). pp = m = n = 1F (W ,V ,T ) = W × V × Tθ = {(1, 1)}

p ∈ F (V ,T )

{w , . . .} ←−−−−−−

w v t

−−−−−−→ {t, . . .}←−−

{v , . . .}

Page 19: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

More About Container-Like Functors

F : Set→ SetFunctor mapF :

∏A,B∈Set(A→ B)→ F (A)→ F (B)

Relator relF :∏

A,B∈Set P (A× B)→ P(F (A)× F (B))

F F

a++f a

F F

aR

a′

mapF f relF R

Container types [Hoogendijk and de Moor 2000]Containers [Abbott et al. 2005]Bounded Natural Functors (BNFs) [Traytel et al. 2012]

Page 20: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

More About Container-Like Functors

F : Set→ SetFunctor mapF :

∏A,B∈Set(A→ B)→ F (A)→ F (B)

Relator relF :∏

A,B∈Set P (A× B)→ P(F (A)× F (B))

F F

a++f a

F F

aR

a′

mapF f relF R

Container types [Hoogendijk and de Moor 2000]Containers [Abbott et al. 2005]Bounded Natural Functors (BNFs) [Traytel et al. 2012]

Page 21: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders (Summary)

Proposal: Binder = Operator on sets F : Setp × Setm × Setn → Setthat is a Map-Restricted Bounded Natural Functor (MRBNF):

w.r.t. arbitrary functions on the p free-variable argumentsw.r.t. injections on the m binding-variable argumentsw.r.t. arbitrary functions on the n “term” arguments

plus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Term-agnostic: Binds any hypothetical terms.

Page 22: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders (Summary)

Proposal: Binder = Operator on sets F : Setp × Setm × Setn → Setthat is a Map-Restricted Bounded Natural Functor (MRBNF):w.r.t. small-support endofunctions on the p free-variable argumentsw.r.t. small-support endobijections on the m binding-vars. argumentsw.r.t. arbitrary functions on the n “term” arguments

plus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Term-agnostic: Binds any hypothetical terms.

Page 23: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders (Summary)

Proposal: Binder = Operator on sets F : Setp × Setm × Setn → Setthat is a Map-Restricted Bounded Natural Functor (MRBNF):w.r.t. small-support endofunctions on the p free-variable argumentsw.r.t. small-support endobijections on the m binding-vars. argumentsw.r.t. arbitrary functions on the n “term” arguments

plus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Term-agnostic: Binds any hypothetical terms.

Page 24: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Constructing Terms from Binders

F : Setp × Setm × Set→ Set

Assume p = m.

Raw terms:

T (V ) = µA. F(V ,V ,A)

v ′ v t©

Alpha-quotiented terms: T (V ) = T (V ) /≡θ

Page 25: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Constructing Terms from Binders

F : Setp × Setm × Set→ Set

Assume p = m.

Raw terms:

T (V ) = µA. F(V ,V ,A)

v ′ v t©

Alpha-quotiented terms: T (V ) = T (V ) /≡θ

Page 26: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Constructing Terms from Binders

F : Setp × Setm × Set→ Set

Assume p = m.

Raw terms: T (V ) = µA. F(V ,V ,A)

v ′ v t©

Alpha-quotiented terms: T (V ) = T (V ) /≡θ

Page 27: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Constructing Terms from Binders

F : Setp × Setm × Set→ Set

Assume p = m.

Raw terms: T (V ) = µA. F(V ,V ,A)

v ′ v t©

Alpha-quotiented terms: T (V ) = T (V ) /≡θ

Page 28: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Inductive Definition of Alpha-Equivalence

F F

w

=

v

∃ f

t

mapT f _ ≡θ _

w ′ v ′ t ′

Equality on the top free variablesPossible bijective renamings of top binding variablesRecursive call factoring in the renamings

Page 29: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Abstract Characterization of Alpha-Quotinented Terms?

T (V ) = µA. F(V ,V ,A) OKT (V ) = T (V ) / ≡θ too low-level

Operators on T:- ctor : F (V ,V ,T (V ))→ T (V ) non-injective constructor- FVarsi : T (V )→ Vi

- mapT functorial action on T w.r.t. bijections

Theorem: (T,FVars,mapT, ctor) is the initial object in a categoryof models U = (U,UFVars,Umap,Uctor) satisfying:

- Umap functorial on bijections- Umap and UFVarsi distribute over Uctor- Umap satisfies congruence w.r.t. UFVarsi

⇓Recursor generalizing the state-of-the-art nominal recursors(Norrish 2004, Pitts 2006, Urban and Berghofer 2006, GP 2017)

Page 30: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Abstract Characterization of Alpha-Quotinented Terms?

T (V ) = µA. F(V ,V ,A) OKT (V ) = T (V ) / ≡θ too low-level

Operators on T:- ctor : F (V ,V ,T (V ))→ T (V ) non-injective constructor- FVarsi : T (V )→ Vi

- mapT functorial action on T w.r.t. bijections

Theorem: (T,FVars,mapT, ctor) is the initial object in a categoryof models U = (U,UFVars,Umap,Uctor) satisfying:

- Umap functorial on bijections- Umap and UFVarsi distribute over Uctor- Umap satisfies congruence w.r.t. UFVarsi

⇓Recursor generalizing the state-of-the-art nominal recursors(Norrish 2004, Pitts 2006, Urban and Berghofer 2006, GP 2017)

Page 31: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Abstract Characterization of Alpha-Quotinented Terms?

T (V ) = µA. F(V ,V ,A) OKT (V ) = T (V ) / ≡θ too low-level

Operators on T:- ctor : F (V ,V ,T (V ))→ T (V ) non-injective constructor- FVarsi : T (V )→ Vi

- mapT functorial action on T w.r.t. bijections

Theorem: (T,FVars,mapT, ctor) is the initial object in a categoryof models U = (U,UFVars,Umap,Uctor) satisfying:

- Umap functorial on bijections- Umap and UFVarsi distribute over Uctor- Umap satisfies congruence w.r.t. UFVarsi

⇓Recursor generalizing the state-of-the-art nominal recursors(Norrish 2004, Pitts 2006, Urban and Berghofer 2006, GP 2017)

Page 32: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Abstract Characterization of Alpha-Quotinented Terms?

Notation: T (V ) = µθA. F(V ,V ,A)

Operators on T:- ctor : F (V ,V ,T (V ))→ T (V ) non-injective constructor- FVarsi : T (V )→ Vi

- mapT functorial action on T w.r.t. bijections

Theorem: (T,FVars,mapT, ctor) is the initial object in a categoryof models U = (U,UFVars,Umap,Uctor) satisfying:

- Umap functorial on bijections- Umap and UFVarsi distribute over Uctor- Umap satisfies congruence w.r.t. UFVarsi

⇓Recursor generalizing the state-of-the-art nominal recursors(Norrish 2004, Pitts 2006, Urban and Berghofer 2006, GP 2017)

Page 33: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Closure Properties for MRBNFsInclude standard type constructors: sums, products, . . .

Include nonfree type constructors: fin. sets, bags, prob. distrib., . . .

Closed under standard least/greatest fixpoints: lists, trees, . . .

Closed under linearization

Closed under binding-aware least/greatest fixpoints (modulobinding dispatchers)“Side effects”: Binding-aware (co)recursors and (co)inductionprinciples (obeying Barendregt’s variable convention)

⇓Modular and flexible specification framework for binding datatypes

Plug and playComplex binders made easy

Page 34: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Closure Properties for MRBNFsInclude standard type constructors: sums, products, . . .

Include nonfree type constructors: fin. sets, bags, prob. distrib., . . .

Closed under standard least/greatest fixpoints: lists, trees, . . .

Closed under linearization

Closed under binding-aware least/greatest fixpoints (modulobinding dispatchers)“Side effects”: Binding-aware (co)recursors and (co)inductionprinciples (obeying Barendregt’s variable convention)

⇓Modular and flexible specification framework for binding datatypes

Plug and playComplex binders made easy

Page 35: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Example: POPLmark Syntax FragmentType-variable α, term-variables x , labels l

Types σ ::= α | . . .Patterns p ::= x : σ | {li = pi

i ∈ 1...n}Terms t ::= x | Λα. t | let p = t1 in t2

Assumptions: Term-variables are pairwise distinct in any pattern.Assumptions: In terms, term-variables coming from patterns andAssumptions: type-variables near Λ’s are binding.

Type (A) = . . .Pattern (A,X ) = (µP. X×Type (A) + FinPFunc (Label,P))@X

Term (A,X ) = µθT . X + A× T + Pattern (A,X )×T 2

= µθT . F (A,X ,A,X ,T )where:

F (A′,X ′,A,X ,T ) = X ′ + A× T + Pattern (A′,X )×T 2

θ = {(1, 1), (2, 1)}

Page 36: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Example: POPLmark Syntax FragmentType-variable α, term-variables x , labels l

Types σ ::= α | . . .Patterns p ::= x : σ | {li = pi

i ∈ 1...n}Terms t ::= x | Λα. t | let p = t1 in t2

Assumptions: Term-variables are pairwise distinct in any pattern.Assumptions: In terms, term-variables coming from patterns andAssumptions: type-variables near Λ’s are binding.

Type (A) = . . .Pattern (A,X ) = (µP. X×Type (A) + FinPFunc (Label,P))@X

Term (A,X ) = µθT . X + A× T + Pattern (A,X )×T 2

= µθT . F (A,X ,A,X ,T )where:

F (A′,X ′,A,X ,T ) = X ′ + A× T + Pattern (A′,X )×T 2

θ = {(1, 1), (2, 1)}

Page 37: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Example: POPLmark Syntax FragmentType-variable α, term-variables x , labels l

Types σ ::= α | . . .Patterns p ::= x : σ | {li = pi

i ∈ 1...n}Terms t ::= x | Λα. t | let _p_ = t1 in t2

Assumptions: Term-variables are pairwise distinct in any pattern.Assumptions: In terms, term-variables coming from patterns andAssumptions: type-variables near Λ’s are binding.

Type (A) = . . .Pattern (A,X ) = (µP. X×Type (A) + FinPFunc (Label,P))@X

Term (A,X ) = µθT . X + A× T + Pattern (A,X )×T 2

= µθT . F (A,X ,A,X ,T )where:

F (A′,X ′,A,X ,T ) = X ′ + A× T + Pattern (A′,X )×T 2

θ = {(1, 1), (2, 1)}

Page 38: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Example: POPLmark Syntax FragmentType-variable α, term-variables x , labels l

Types σ ::= α | . . .Patterns p ::= x : σ | {li = pi

i ∈ 1...n}Terms t ::= x | Λα. t | let _p_ = t1 in t2

Assumptions: Term-variables are pairwise distinct in any pattern.Assumptions: In terms, term-variables coming from patterns andAssumptions: type-variables near Λ’s are binding.

Type (A) = . . .Pattern (A,X ) = (µP. X×Type (A) + FinPFunc (Label,P))@X

Term (A,X ) = µθT . X + A× T + Pattern (A,X )×T 2

= µθT . F (A,X ,A,X ,T )where:

F (A′,X ′,A,X ,T ) = X ′ + A× T + Pattern (A′,X )×T 2

θ = {(1, 1), (2, 1)}

Page 39: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Related Work: 1999

A lot of work on categorical generalizations of the “nameless”,De Bruijn representation, pioneered by:

Fiore et al. (LICS’99)Hofmann (LICS’99)Bird and Paterson (J. Func. Prog. ’99)Altenkirch and Reus (CSL’99)

By contrast, our work is within the “nameful” paradigm,generalizing Nominal Logic (Gabbay and Pitts (LICS’99))

(Higher Order Abstract Syntax (HOAS) – the third main paradigm)

Page 40: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Related Work: Relevant Classes of Functors

Dependent Polynomial=

Indexed ContainerMRBNF

Accessible=

Quotient of Polynomial

BNF

(Infinitary) Analytic=

Quotient Container

Polynomial=

Container

Page 41: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Related Work: Binders in the Isabelle Ecosystem

λ→

∀=Is

abelle

β

α

Isabelle Nominal2 [Urban and Kaliszyk 2012]- Good user support- Complex binders via syntactic format

Our improvements (once the implementation is ready):- Expressiveness- Modularity- Better integration with Isabelle’s standard datatypes (whichare based on BNFs)

Page 42: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Bindings as Bounded Natural Functors

Jasmin Blanchette, Lorenzo Gheri, Andrei Popescu, Dmitriy Traytel

Vrije Universiteit Amsterdam Middlesex University London ETH Zürich

https://www.youtube.com/watch?v=gkq2ONqQ2MI

Page 43: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Reserve Slides

Page 44: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

The Linearization Operator @

List (A)@A = {xs ∈ List (A) | ∀i , j . i 6= j −→ xs i 6= xs j}

Let F : Set→ Set be a BNF.

!A : A→ Unit = {∗}shape = mapF !A : F (A)→ F (Unit)

F F

a ** ∗

How about: p ∈ F (A) linear... if ∀q. shape q = shape p −→ |setF q| ≤ |setF p|

Works for finitary functors.

Fails in general: For F = Stream, [0, 0, 1, 2, 3, . . .] ∈ F (IN) linear.

Page 45: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

The Linearization Operator @

List (A)@A = {xs ∈ List (A) | ∀i , j . i 6= j −→ xs i 6= xs j}

Let F : Set→ Set be a BNF.

!A : A→ Unit = {∗}shape = mapF !A : F (A)→ F (Unit)

F F

a ** ∗

How about: p ∈ F (A) linear... if ∀q. shape q = shape p −→ |setF q| ≤ |setF p|

Works for finitary functors.

Fails in general: For F = Stream, [0, 0, 1, 2, 3, . . .] ∈ F (IN) linear.

Page 46: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

The Linearization Operator @

List (A)@A = {xs ∈ List (A) | ∀i , j . i 6= j −→ xs i 6= xs j}

Let F : Set→ Set be a BNF.

!A : A→ Unit = {∗}shape = mapF !A : F (A)→ F (Unit)

F F

a ** ∗

How about: p ∈ F (A) linear... if ∀q. shape q = shape p −→ |setF q| ≤ |setF p|

Works for finitary functors.

Fails in general: For F = Stream, [0, 0, 1, 2, 3, . . .] ∈ F (IN) linear.

Page 47: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

The Linearization Operator @

List (A)@A = {xs ∈ List (A) | ∀i , j . i 6= j −→ xs i 6= xs j}

Let F : Set→ Set be a BNF.

!A : A→ Unit = {∗}shape = mapF !A : F (A)→ F (Unit)

F F

a ** ∗

Better: p ∈ F (A) linear... if ∀q. shape q = shape p −→ ∃f : A→ A. mapF f p = q

Works in general.

Gives us back a sub-functor, F@, of F’s restriction to bijections.

Page 48: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Modularity

Let F : Setm × Setm × Set→ Set be an MRBNF.

T (V ) = µθA. F (V ,V ,A)

Is T also an MRBNF?

setTi := FVarsi

On bijections, mapT lifted from mapT.But want mapT non-bijective/injective functions too!

⇓mapT := the capture-avoiding substitution

Problem: Substitution only behaves well on functions of small support.

So we have F functorial w.r.t. (arbitrary) functionsimplies T functorial only w.r.t. small-support functions.

Page 49: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Modularity

Let F : Setm × Setm × Set→ Set be an MRBNF.

T (V ) = µθA. F (V ,V ,A)

Is T also an MRBNF?

setTi := FVarsi

On bijections, mapT lifted from mapT.But want mapT non-bijective/injective functions too!

⇓mapT := the capture-avoiding substitution

Problem: Substitution only behaves well on functions of small support.

So we have F functorial w.r.t. (arbitrary) functionsimplies T functorial only w.r.t. small-support functions.

Page 50: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Modularity

Let F : Setm × Setm × Set→ Set be an MRBNF.

T (V ) = µθA. F (V ,V ,A)

Is T also an MRBNF?

setTi := FVarsi

On bijections, mapT lifted from mapT.But want mapT non-bijective/injective functions too!

⇓mapT := the capture-avoiding substitution

Problem: Substitution only behaves well on functions of small support.

So we have F functorial w.r.t. (arbitrary) functionsimplies T functorial only w.r.t. small-support functions.

Page 51: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Solution

Proposal: Binder = Operator on sets F : Setp × Setm × Setn → Setthat is a Map-Restricted Bounded Natural Functor (MRBNF):

w.r.t. arbitrary functions on the p free-variable argumentsw.r.t. injections on the m binding-variable argumentsw.r.t. arbitrary functions on the n “term” arguments

plus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Proposal: Binder = Operator on sets F : Setp × Setm × Setn → Setthat is a Map-Restricted Bounded Natural Functor (MRBNF):w.r.t. small-support functions on the p free-variable argumentsw.r.t. small-support injections on the m binding-vars. argumentsw.r.t. arbitrary functions on the n “term” arguments

plus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Page 52: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F?

How about Finitary Natural Functor (FNF)?

Functor: for fi : Vi → V ′i , gj : Tj → T ′jFunctor: mapF f g : F (V ,T )→ F (V ′,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk )

setiF :F (V ,T )→ P (Vi ) setm+jF :F (V ,T )→ P (Tj )

Finitary: setiF (. . .), setm+jF (. . .) finite

blah

Problem 1:let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Want to disallow repetitions, as in “let rec v = t1 and v = t2 in t” yet[(v , t1), (v , t2)] ∈ List (V × T )

Solution: Replace List (V × T ) with List (V × T )@V

where “@V ” means “linearize on V ”, i.e., “exclude V -repetitions”

Page 53: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Finitary Natural Functor (FNF)?

Functor: for fi : Vi → V ′i , gj : Tj → T ′jFunctor: mapF f g : F (V ,T )→ F (V ′,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk )

setiF :F (V ,T )→ P (Vi ) setm+jF :F (V ,T )→ P (Tj )

Finitary: setiF (. . .), setm+jF (. . .) finite

blah

Problem 1:let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Want to disallow repetitions, as in “let rec v = t1 and v = t2 in t” yet[(v , t1), (v , t2)] ∈ List (V × T )

Solution: Replace List (V × T ) with List (V × T )@V

where “@V ” means “linearize on V ”, i.e., “exclude V -repetitions”

Page 54: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Bounded Natural Functor (BNF)?

Functor: for fi : Vi → V ′i , gj : Tj → T ′jFunctor: mapF f g : F (V ,T )→ F (V ′,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk )

setiF :F (V ,T )→ P (Vi ) setm+jF :F (V ,T )→ P (Tj )

Bounded: For some cardinal bdF

setkF (. . .) ≤ bdF

setiF (. . .) ≤ bdF setm+jF (. . .) ≤ bdF

Problem 1:let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Want to disallow repetitions, as in “let rec v = t1 and v = t2 in t” yet[(v , t1), (v , t2)] ∈ List (V × T )

Solution: Replace List (V × T ) with List (V × T )@V

where “@V ” means “linearize on V ”, i.e., “exclude V -repetitions”

Page 55: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Bounded Natural Functor (BNF)?

Functor: for fi : Vi → V ′i , gj : Tj → T ′jFunctor: mapF f g : F (V ,T )→ F (V ′,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk )

setiF :F (V ,T )→ P (Vi ) setm+jF :F (V ,T )→ P (Tj )

Bounded: For some cardinal bdF

setkF (. . .) ≤ bdF

setiF (. . .) ≤ bdF setm+jF (. . .) ≤ bdF

Problem 1:let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Want to disallow repetitions, as in “let rec v = t1 and v = t2 in t” yet[(v , t1), (v , t2)] ∈ List (V × T )

Solution: Replace List (V × T ) with List (V × T )@V

where “@V ” means “linearize on V ”, i.e., “exclude V -repetitions”

Page 56: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Bounded Natural Functor (BNF)?

Functor: for fi : Vi → V ′i , gj : Tj → T ′jFunctor: mapF f g : F (V ,T )→ F (V ′,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk )

setiF :F (V ,T )→ P (Vi ) setm+jF :F (V ,T )→ P (Tj )

Bounded: For some cardinal bdF

setkF (. . .) ≤ bdF

setiF (. . .) ≤ bdF setm+jF (. . .) ≤ bdF

Problem 1:let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )× Tθ = {(1, 1)}

Want to disallow repetitions, as in “let rec v = t1 and v = t2 in t” yet[(v , t1), (v , t2)] ∈ List (V × T )

Solution: Replace List (V × T ) with List (V × T )@V

where “@V ” means “linearize on V ”, i.e., “exclude V -repetitions”

Page 57: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Bounded Natural Functor (BNF)?

Functor: for fi : Vi → V ′i , gj : Tj → T ′jFunctor: mapF f g : F (V ,T )→ F (V ′,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk )

setiF :F (V ,T )→ P (Vi ) setm+jF :F (V ,T )→ P (Tj )

Bounded: For some cardinal bdF

setkF (. . .) ≤ bdF

setiF (. . .) ≤ bdF setm+jF (. . .) ≤ bdF

Problem 1:let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )@V × Tθ = {(1, 1)}

Want to disallow repetitions, as in “let rec v = t1 and v = t2 in t” yet[(v , t1), (v , t2)] ∈ List (V × T )

Solution: Replace List (V × T ) with List (V × T )@V

where “@V ” means “linearize on V ”, i.e., “exclude V -repetitions”

Page 58: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Bounded Natural Functor (BNF)?

Functor: for fi : Vi → Vi bijections, gj : Tj → T ′jFunctor: mapF f g : F (V ,T )→ F (V ′,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk )

setiF :F (V ,T )→ P (Vi ) setm+jF :F (V ,T )→ P (Tj )

Bounded: For some cardinal bdF

setkF (. . .) ≤ bdF

setiF (. . .) ≤ bdF setm+jF (. . .) ≤ bdF

Problem 1:let rec v1 = t1 and . . . and vk = tk in t

m = n = 1F (V ,T ) = List (V × T )@V × Tθ = {(1, 1)}

Want to disallow repetitions, as in “let rec v = t1 and v = t2 in t” yet[(v , t1), (v , t2)] ∈ List (V × T )

Solution: Replace List (V × T ) with List (V × T )@V

where “@V ” means “linearize on V ”, i.e., “exclude V -repetitions”

Page 59: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setp × Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Bounded Natural Functor (BNF)?

Functor: for fi : Vi → Vi bijections, gj : Tj → T ′jFunctor: mapF f g : F (V ,T )→ F (V ′,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk )

setiF :F (V ,T )→ P (Vi ) setm+jF :F (V ,T )→ P (Tj )

Bounded: For some cardinal bdF

setkF (. . .) ≤ bdF

setiF (. . .) ≤ bdF setm+jF (. . .) ≤ bdF

Problem 2:

w (v). p

p = m = n = 1F (W ,V ,T ) = W × V × Tθ = {(1, 1)}

Free variables are currently completely ignored.

Solution: Have free-variable args. in addition to binding-variable args.

blah

Page 60: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setp × Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Bounded Natural Functor (BNF)?

Functor: for hk : Wk →Wk ,fi : Vi → Vi bijections, gj : Tj → T ′jFunctor: mapF h f g : F (W ,V ,T )→ F (W ,V ,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk ) setp+iF :F (W ,V ,T )→ P (Vi ) setp+m+j

F :F (W ,V ,T )→ P (Tj )

Bounded: For some cardinal bdFsetkF (. . .) ≤ bdF setp+i

F (. . .) ≤ bdF setp+m+jF (. . .) ≤ bdF

Problem 2:

w (v). pp = m = n = 1F (W ,V ,T ) = W × V × Tθ = {(1, 1)}

Free variables are currently completely ignored.Solution: Have free-variable args. in addition to binding-variable args.

blah

Page 61: VrijeUniversiteitAmsterdamMiddlesexUniversityLondonETHZüri ...andreipopescu.uk/pdf/slides_BindingsAsBNFs.pdf · WhatisaBinder? Severalveryexpressivesyntacticformats: C Ml[Pottier2006]

Structure of Binders: More DetailsProposal: Binder = Operator on sets F : Setp × Setm × Setn → Setplus binding dispatcher relation θ ⊆ {1, . . . ,m} × {1, . . . , n}.

Can assume more about F? How about Bounded Natural Functor (BNF)?

Functor: for hk : Wk →Wk ,fi : Vi → Vi bijections, gj : Tj → T ′jFunctor: mapF h f g : F (W ,V ,T )→ F (W ,V ,T ′)Natural (container-like): there exist the natural transformations

setkF :F (W ,V ,T )→ P (Wk ) setp+iF :F (W ,V ,T )→ P (Vi ) setp+m+j

F :F (W ,V ,T )→ P (Tj )

Bounded: For some cardinal bdFsetkF (. . .) ≤ bdF setp+i

F (. . .) ≤ bdF setp+m+jF (. . .) ≤ bdF

Problem 2:

w (v). pp = m = n = 1F (W ,V ,T ) = W × V × Tθ = {(1, 1)}

Free variables are currently completely ignored.Solution: Have free-variable args. in addition to binding-variable args.

blah