Reference. A type- and scope-safe universe of syntaxes with binding: their semantics and proofs
The syntax of almost every programming language includes a notion of binder and corresponding bound occurrences, along with the accompanying notions of α-equivalence, capture-avoiding substitution, typing contexts, runtime environments, and so on. In the past, implementing and reasoning about programming languages required careful handling to maintain the correct behaviour of bound variables. Modern programming languages include features that enable constraints like scope safety to be expressed in types. Nevertheless, the programmer is still forced to write the same boilerplate over again for each new implementation of a scope-safe operation (e.g., renaming, substitution, desugaring, printing), and then again for correctness proofs. We present an expressive universe of syntaxes with binding and demonstrate how to (1) implement scope-safe traversals once and for all by generic programming; and (2) how to derive properties of these traversals by generic proving. Our universe description, generic traversals and proofs, and our examples have all been formalised in Agda and are available in the accompanying material available online at https://github.com/gallais/generic-syntax .
Cite
Cited by (4)
Modular abstract syntax trees (MAST): substitution tensors with second-class sorts fiore-2025-modular
We adapt Fiore, Plotkin, and Turi’s treatment of abstract syntax with binding, substitution, and holes to account for languages with second-class sorts. These situations include programming calculi such as the Call-by-Value lambda-calculus (CBV) and Levy’s Call-by-Push-Value (CBPV). Prohibiting second-class sorts from appearing in variable contexts changes the characterisation of the abstract syntax from monoids in monoidal categories to actions in actegories. We reproduce much of the development through bicategorical arguments. We apply the resulting theory by proving substitution lemmata for varieties of CBV.
Semantic analysis of normalisation by evaluation for typed lambda calculus fiore-2022-semantic
This paper studies normalisation by evaluation for typed lambda calculus from a categorical and algebraic viewpoint. The first part of the paper analyses the lambda definability result of Jung and Tiuryn via Kripke logical relations and shows how it can be adapted to unify definability and normalisation, yielding an extensional normalisation result. In the second part of the paper, the analysis is refined further by considering intensional Kripke relations (in the form of Artin–Wraith glueing) and shown to provide a function for normalising terms, casting normalisation by evaluation in the context of categorical glueing. The technical development includes an algebraic treatment of the syntax and semantics of the typed lambda calculus that allows the definition of the normalisation function to be given within a simply typed metatheory. A normalisation-by-evaluation program in a dependently typed functional programming language is synthesised.
Formal metatheory of second-order abstract syntax fiore-2022-formal
Despite extensive research both on the theoretical and practical fronts, formalising, reasoning about, and implementing languages with variable binding is still a daunting endeavour – repetitive boilerplate and the overly complicated metatheory of capture-avoiding substitution often get in the way of progressing on to the actually interesting properties of a language. Existing developments offer some relief, however at the expense of inconvenient and error-prone term encodings and lack of formal foundations. We present a mathematically-inspired language-formalisation framework implemented in Agda. The system translates the description of a syntax signature with variable-binding operators into an intrinsically-encoded, inductive data type equipped with syntactic operations such as weakening and substitution, along with their correctness properties. The generated metatheory further incorporates metavariables and their associated operation of metasubstitution, which enables second-order equational/rewriting reasoning. The underlying mathematical foundation of the framework – initial algebra semantics – derives compositional interpretations of languages into their models satisfying the semantic substitution lemma by construction.
A Framework for Substructural Type Systems wood-2022-a
Mechanisation of programming language research is of growing interest, and the act of mechanising type systems and their metatheory is generally becoming easier as new techniques are invented. However, state-of-the-art techniques mostly rely on structurality of the type system — that weakening, contraction, and exchange are admissible and variables can be used unrestrictedly once assumed. Linear logic, and many related subsequent systems, provide motivations for breaking some of these assumptions. We present a framework for mechanising the metatheory of certain substructural type systems, in a style resembling mechanised metatheory of structural type systems. The framework covers a wide range of simply typed syntaxes with semiring usage annotations, via a metasyntax of typing rules. The metasyntax for the premises of a typing rule is related to bunched logic, featuring both sharing and separating conjunction, roughly corresponding to the additive and multiplicative features of linear logic. We use the uniformity of syntaxes to derive type system-generic renaming, substitution, and a form of linearity checking.
Cites 93 works (8 here)
With notes (8)
agdarsec — total parser combinators allais_2018
Type-and-scope safe programs and their proofs allais-2017-type
Indexed containers altenkirch_indexed_2015
We show that the syntactically rich notion of strictly positive families can be reduced to a core type theory with a fixed number of type constructors exploiting the novel notion of indexed containers. As a result, we show indexed containers provide normal forms for strictly positive families in much the same way that containers provide normal forms for strictly positive types. Interestingly, this step from containers to indexed containers is achieved without having to extend the core type theory. Most of the construction presented here has been formalized using the Agda system.
Total parser combinators danielssonTotalParserCombinators2010
A monadic parser combinator library which guarantees termination of parsing, while still allowing many forms of left recursion, is described. The library’s interface is similar to those of many other parser combinator libraries, with two important differences: one is that the interface clearly specifies which parts of the constructed parsers may be infinite, and which parts have to be finite, using dependent types and a combination of induction and coinduction; and the other is that the parser type is unusually informative.
The library comes with a formal semantics, using which it is proved that the parser combinators are as expressive as possible. The implementation is supported by a machine-checked correctness proof.
The essence of the Iterator pattern gibbons-2009-the
The Iterator pattern gives a clean interface for element-by-element access to a collection, independent of the collection’s shape. Imperative iterations using the pattern have two simultaneous aspects: mapping and accumulating . Various existing functional models of iteration capture one or other of these aspects, but not both simultaneously. We argue that C. McBride and R. Paterson’s applicative functors (Applicative programming with effects, J. Funct. Program. , 18 (1): 1–13, 2008), and in particular the corresponding traverse operator, do exactly this, and therefore capture the essence of the Iterator pattern. Moreover, they do so in a way that nicely supports modular programming. We present some axioms for traversal, discuss modularity concerns and illustrate with a simple example, the wordcount problem.
Applicative programming with effects mcbride-2008-applicative
In this article, we introduce Applicative functors – an abstract characterisation of an applicative style of effectful programming, weaker than Monads and hence more widespread. Indeed, it is the ubiquity of this programming pattern that drew us to the abstraction. We retrace our steps in this article, introducing the applicative pattern by diverse examples, then abstracting it to define the Applicative type class and introducing a bracket notation that interprets the normal application syntax in the idiom of an Applicative functor. Furthermore, we develop the properties of applicative functors and the generic operations they support. We close by identifying the categorical structure of applicative functors and examining their relationship both with Monads and with Arrow.
The view from the left mcbride-2004-the
Pattern matching has proved an extremely powerful and durable notion in functional programming. This paper contributes a new programming notation for type theory which elaborates the notion in various ways. First, as is by now quite well-known in the type theory community, definition by pattern matching becomes a more discriminating tool in the presence of dependent types, since it refines the explanation of types as well as values. This becomes all the more true in the presence of the rich class of datatypes known as inductive families (Dybjer, 1991). Secondly, as proposed by Peyton Jones (1997) for Haskell, and independently rediscovered by us, subsidiary case analyses on the results of intermediate computations, which commonly take place on the right-hand side of definitions by pattern matching, should rather be handled on the left. In simply-typed languages, this subsumes the trivial case of Boolean guards; in our setting it becomes yet more powerful. Thirdly, elementary pattern matching decompositions have a well-defined interface given by a dependent type; they correspond to the statement of an induction principle for the datatype. More general, user-definable decompositions may be defined which also have types of the same general form. Elementary pattern matching may therefore be recast in abstract form, with a semantics given by translation. Such abstract decompositions of data generalize Wadler’s (1987) notion of ‘view’. The programmer wishing to introduce a new view of a type , and exploit it directly in pattern matching, may do so via a standard programming idiom. The type theorist, looking through the Curry–Howard lens, may see this as proving a theorem , one which establishes the validity of a new induction principle for . We develop enough syntax and semantics to account for this high-level style of programming in dependent type theory. We close with the development of a typechecker for the simply-typed lambda calculus, which furnishes a view of raw terms as either being well-typed, or containing an error. The implementation of this view is ipso facto a proof that typechecking is decidable.
Abstract syntax and variable binding fiore_etal_nd
We develop a theory of abstract syntax with variable binding. To every binding signature we associate a category of models consisting of variable sets endowed with compatible algebra and substitution structures. The syntax generated by the signature is the initial model. This gives a notion of initial algebra semantics encompassing the traditional one; besides compositionality, it automatically verifies the semantic substitution lemma.
External (85)
- Stitch: the sound type-indexed type checker (functional pearl) (2020)
- POPLMark reloaded: Mechanizing proofs by logical relations (2019)
- Verifying Type-and-Scope Safe Program Transformations (Master's thesis) (2019)
- Binder aware recursion over well-scoped de Bruijn syntax (2018)
- Programming Language Foundations in Agda (2018)
- Triangulating context lemmas (2018)
- From algebra to abstract machine: a verified generic construction (2018)
- Context constrained computation (2018)
- Intrinsically-typed definitional interpreters for imperative languages (2017)
- POPLMark Reloaded (LFMTP 2017 workshop version) (2017)
- On the Formalisation of the Metatheory of the Lambda Calculus and Languages with Binders (PhD thesis) (2017)
- A fibrational framework for substructural and modal logics (2017)
- The Coq proof assistant reference manual, version 8.6 (2017)
- Verified Functional Programming in Agda (2016)
- Needle & Knot: Binder Boilerplate Tied Up (2016)
- A case-study in programming coinductive proofs: Howe's method (2016)
- Monads need not be endofunctors (2015)
- The Lean Theorem Prover (System Description) (2015)
- An algebraic approach to typechecking and elaboration (blog post) (2015)
- Relative monads formalised (2014)
- A Core Quantitative Coeffect Calculus (2014)
- Bounded Linear Types in a Resource Semiring (2014)
- Coeffects: a calculus of context-dependent computation (2014)
- Transporting functions across ornaments (2014)
- Automatically Generated Infrastructure for De Bruijn Syntaxes (2013)
- Idris, a general-purpose dependently typed programming language: Design and implementation (2013)
- A nanopass framework for commercial compiler development (2013)
- Copatterns: programming infinite structures by observations (2013)
- A cosmology of datatypes: reusability and dependent types (PhD thesis) (2013)
- GMeta: A Generic Formal Metatheory Framework for First-Order Representations (2012)
- Generic conversions of abstract syntax representations (2012)
- The Locally Nameless Representation (2011)
- Strongly Typed Term Representations in Coq (2011)
- Binders unbound (2011)
- Associativity for free! (2011)
- Generic Programming With Binders and Scope (Master's thesis) (2011)
- Generic programming with indexed functors (2011)
- The gentle art of levitation (2010)
- MiniAgda: Integrating Sized and Dependent Types (2010)
- A generic deriving mechanism for Haskell (2010)
- Nested Abstract Syntax in Coq (2010)
- Initial Algebra Semantics for Cyclic Sharing Structures (2009)
- Dependently typed programming in Agda (2009)
- Type checking and normalisation (PhD thesis) (2009)
- Parametric higher-order abstract syntax for mechanized semantics (2008)
- Data types à la carte (2008)
- Exploring the Regular Tree Types (2006)
- A verified staged interpreter is a verified compiler (2006)
- Representing cyclic structures as nested datatypes (2006)
- Mechanized Metatheory for the Masses: The PoplMark Challenge (2005)
- Toward a general theory of names: binding and scope (2005)
- δ for data: Differentiating data structures (2005)
- Tridirectional typechecking (2004)
- Lecture 17: Bidirectional type checking (15-312 lecture notes) (2004)
- Universes for generic programs and proofs in dependent type theory (2003)
- On bunched typing (2003)
- Generic Programming within Dependently Typed Programming (2003)
- A New Approach to Abstract Syntax with Variable Binding (2002)
- A Formalised Proof of the Soundness and Completeness of a Simply Typed Lambda-Calculus with Explicit Substitutions (2002)
- Derivable Type Classes (2001)
- Local type inference (2000)
- Monadic Presentations of Lambda Terms Using Generalized Inductive Types (1999)
- A Finite Axiomatization of Inductive-Recursive Definitions (1999)
- de Bruijn notation as a nested datatype (1999)
- A coherence theorem for Martin-Löf's type theory (1998)
- The Definition of Standard ML (1997)
- The Zipper (1997)
- Intuitionistic model constructions and normalization proofs (1997)
- Shrinking lambda expressions in linear time (1997)
- Building domain-specific embedded languages (1996)
- Dual intuitionistic linear logic (1996)
- Categorical reconstruction of a reduction free normalization proof (1995)
- Substitution: A formal methods case study using monads and transformations (1994)
- The groupoid model refutes uniqueness of identity proofs (1994)
- Inductive families (1994)
- A generic account of continuation-passing styles (1994)
- Program extraction from normalization proofs (1993)
- A term calculus for Intuitionistic Linear Logic (1993)
- An inverse of the evaluation functional for typed lambda-calculus (1991)
- Kripke-style models for typed lambda calculus (1991)
- Notions of computation and monads (1991)
- Deforestation: transforming programs to eliminate trees (1990)
- Data structures and program transformation (1990)
- Views: a way for pattern matching to cohabit with data abstraction (1987)
- Constructive Mathematics and Computer Programming (1982)