abstract syntax and variable binding
play

Abstract Syntax and Variable Binding (Extended Abstract) Marcelo - PDF document

Abstract Syntax and Variable Binding (Extended Abstract) Marcelo Fiore Gordon Plotkin Daniele Turi COGS LFCS LFCS Univ. of Sussex Univ. of Edinburgh Univ. of Edinburgh Abstract inverse is analytic syntax. Finally, in the recursive


  1. Abstract Syntax and Variable Binding (Extended Abstract) Marcelo Fiore Gordon Plotkin Daniele Turi ∗ COGS LFCS LFCS Univ. of Sussex Univ. of Edinburgh Univ. of Edinburgh Abstract inverse is analytic syntax. Finally, in the recursive type view [32], the initial algebra is obtained as the solution to a recursive (set) equation; this leads one to a treatment of We develop a theory of abstract syntax with variable syntax within programming languages as exemplified in the binding. To every binding signature we associate a cat- egory of models consisting of variable sets endowed with ML/LCF approach [15]. compatible algebra and substitution structures. The syntax The first-order view can be problematic. In particu- generated by the signature is the initial model. This gives a lar, when dealing with context-sensitive aspects of syn- notion of initial algebra semantics encompassing the tradi- tax, it does not account satisfactorily for variable bind- tional one; besides compositionality, it automatically veri- ing , with its allied notions of scope, free and bound oc- currences, α -equivalence, production of fresh variables, fies the semantic substitution lemma. and substitution ( e.g. , in λ -calculus, CCS with value passing, π -calculus, logical quantifiers, and derivative and integral expressions). Useful context-sensitive extensions Introduction of BNF certainly exist, such as attribute grammars and van Wijngaarden grammars; however, they do not in them- It has long been recognised that the essential syntactical selves give an account of deep structure. structure of programming languages is not that given by One proposal for an abstract treatment, originating with their concrete or surface syntax—as expressed, say, by a Church [7], is that of higher-order abstract syntax ; there language description in BNF oriented to parsing (there the one uses the binding apparatus provided by the typed parse trees contain much information useless for language λ -calculus to express all other forms of binding—see [29, processing). Rather, the deep structure of a phrase should 27, 30, 28]. Normal forms (of ground type) play the rˆ ole reflect its semantic import. of first-order terms, but with first-order signatures being McCarthy [24] coined the term abstract syntax for such replaced by second-order ones. (The binding analogue structure, which is typically given as a tree with its top node of trees is provided by the term graphs first introduced labelled by the main semantic constituent, or, equivalently, by Wadsworth—see, e.g. , [17].) A form of analytic syn- by a term of first-order logic. Abstract syntax has both syn- tax is given by matching or unification in associated lo- thetic and analytic aspects: the former concerns the con- gic programming languages [27, 30]. In implementations, structors needed to form phrases, the latter the destructors De Bruijn’s terms [9] are used to provide “ α -equivalence ( predicates and selectors ) needed to take them apart [21]. normal forms”. Burstall [6] contributed structural recursion —a generalised Unfortunately, in the higher-order abstract syntax ap- form of primitive recursion—to analytic syntax, with an as- proach, many of the desirable properties mentioned above, sociated principle of structural induction . such as accounts of structural recursion and induction, and The algebraic point of view of the ADJ group [14] (see recursive equations for abstract syntax, are missing, or at also [32]) regards abstract syntax as the initial algebra (of least not fully developed (see [26, 25, 10]). the constructors) and semantics as the unique homomorph- In this paper, we provide a (categorical) algebraic view ism to a semantic algebra (the model ). Structural recursion of syntax with variable binding. The analogue to universal then arises from initiality. The categorical view regards the algebra is the theory of binding algebras originating in the algebras as those of an associated signature functor: the ini- work of Aczel [1]—see also [20, 31, 37]. We replace algeb- tial algebra has an isomorphism as structure map and its ras over sets by binding algebras over variable sets . Form- ally, variable sets are (covariant) presheaves and the funda- ∗ Research supported by the EU TMR research programme.

  2. mental idea is to turn contexts into the “index category” of out. In particular, we envisage a type theory based on the the presheaves. internal language of our semantic universe for manipulating We obtain a notion of binding signature in which bind- abstract syntax with binding. Again, structural induction ing is again expressed by second-order types, but now us- principles for reasoning about abstract syntax with binding ing a special presheaf of variables or, equivalently, by a should be available within our framework. first-order signature extended with a notion of differenti- Second, the investigation of more sophisticated syntax in ation ( cf. [16]). Our models, the binding algebras , are then our setting will be pursued. Multi-sorted binding signatures (like the simply typed λ -calculus) can be easily accommod- presheaves endowed with both an algebra structure (corres- ated; various linear settings ( cf. operads [22]), in contrast to ponding to the operations in the signature) and a substitution the cartesian one explored here, also seem to fit; type theor- structure compatible with each other. ies with dependent types are yet to be tackled. Connections Abstract syntax is the initial such model, with the algebra between our approach and the general theory of substitution structure obtained as the solution to a recursive (presheaf) provided by clubs [18, 19] will also be investigated. equation and substitution defined by an associated structural Third, theories of operational semantics with binding recursion. The unique homomorphism from the syntax to will be developed along the lines of [36]. Preliminary res- another model ( initial algebra semantics ) preserves the con- ults indicate that some interesting syntactic formats of well- structors ( i.e. , is compositional) and the extra substitution behaved operational rules for languages with variable bind- structure ( i.e. , verifies the semantic substitution lemma). ing can be obtained. Organisation of the paper. We start in Section 1 by ad- vocating the use of the category of (covariant) presheaves 1. The universe of types Set F as a suitable mathematical universe in which to deal with syntax with variable binding. The index category F We present the universe of types within which we work. is a skeleton of the category of finite sets and functions; Our intent is to consider a notion of type broad enough to it provides a notion of cartesian context allowing for ex- encompass syntax with variable binding (and, more gener- change, weakening, and contraction. The structure of Set F ally, algebras for binding signatures) in a framework with relevant to modelling variable binding is studied in detail. rich type structure ( i.e. , type constructors and operations on The study of signatures with variable binding in our types). To motivate our choice we start by examining the framework is carried out in Section 2. Our main result here structure of the set of λ -terms. is that the presheaf of terms (with binders) associated to a (binding) signature has an abstract universal characterisa- Λ . In the course of our discussion we will consider the set tion as a free algebra over a presheaf of variables. This res- of (untyped) λ -terms Λ Var given by the following grammar. ult is exploited in two directions: to give implementations of ( i ∈ N + ) x ∈ Var ::= x i , abstract syntax (with variable binding) ` a la De Bruijn, and x | λx.t ′ | t 1 t 2 t ∈ Λ Var ::= . to provide semantics by initiality. These two applications are exemplified using the λ -calculus. In untyped settings, the treatment of the operator λ as a Section 3 is devoted to substitution. We treat both binder is typically dealt with by introducing the notion single-variable and simultaneous substitution. The former of free/bound variable. However, as is well-known and is handled by introducing the notion of substitution al- commonly used in typed settings, this information may be gebra ; the latter first by the elementary abstract clones and presented by judgements, consisting of a term together with then, more abstractly, as certain monoids in the category of a context, subject to a well-formedness condition. To sim- presheaves. The three presentations are shown to be equi- plify the exposition we will consider the following well- valent. We also define two “categorical programs” for sub- formedness rules which provide canonical representatives stitution by structural recursion. for α -equivalence classes of λ -terms by the method of In Section 4, we define the category of models of a bind- De Bruijn levels [9]. ing signature; the presheaf of terms is the initial such model. We exemplify the corresponding initial algebra semantics 1 ≤ i ≤ n x 1 , . . . , x n , x n +1 ⊢ t again using the λ -calculus. This semantics, besides being x 1 , . . . , x n ⊢ x i x 1 , . . . , x n ⊢ λx n +1 .t compositional , automatically verifies the semantic substitu- (1) x 1 , . . . , x n ⊢ t 1 x 1 , . . . , x n ⊢ t 2 tion lemma . x 1 , . . . , x n ⊢ t 1 t 2 Future work. Various directions for further work are pos- sible; we mention but a few here. First, the syntactic coun- Conceptually, the passage from the approach based on terpart of our treatment of substitution by categorical struc- free/bound variables to the one based on contexts consists � � P (Var) in turning the free-variable function FV : Λ Var tural recursion ( i.e. , parameterised initiality) will be worked

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend