Abstract
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.
Supplemental Material
- M. Abadi, L. Cardelli, P.-L. Curien, and J.-J. Levy. 1989. Explicit Substitutions. In Proceedings of the 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 1990. ACM Press, 31–46. https://doi.org/10.1145/96709.96712 Google Scholar
Digital Library
- Andreas Abel. 2010. MiniAgda: Integrating Sized and Dependent Types. arxiv:1012.4896. arxiv:1012.4896Google Scholar
- Andreas Abel, Guillaume Allais, Aliya Hameer, Brigitte Pientka, Alberto Momigliano, Steven Schäfer, and Kathrin Stark. 2019. PoplMark reloaded: Mechanizing proofs by logical relations. Journal of Functional Programming, 29 (2019), e19. https://doi.org/10.1017/S0956796819000170 Google Scholar
Cross Ref
- Peter Aczel. 1978. A General Church–Rosser Theorem. http://www.ens-lyon.fr/LIP/REWRITING/MISC/AGeneralChurch-RosserTheorem.pdf Unpublished note.Google Scholar
- Guillaume Allais, Robert Atkey, James Chapman, Conor McBride, and James McKinna. 2021. A type- and scope-safe universe of syntaxes with binding: their semantics and proofs. Journal of Functional Programming, 31 (2021), e22. https://doi.org/10.1017/S0956796820000076 Google Scholar
Cross Ref
- Guillaume Allais, James Chapman, Conor McBride, and James McKinna. 2017. Type-and-Scope Safe Programs and Their Proofs. In Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs (CPP 2017). ACM Press, 195–207. https://doi.org/10.1145/3018610.3018613 Google Scholar
Digital Library
- Thorsten Altenkirch, Neil Ghani, Peter Hancock, Conor McBride, and Peter Morris. 2015. Indexed containers. Journal of Functional Programming, 25 (2015), e5. https://doi.org/10.1017/S095679681500009X Google Scholar
Cross Ref
- Thorsten Altenkirch and Bernhard Reus. 1999. Monadic Presentations of Lambda Terms Using Generalized Inductive Types. In Proceedings of the 13th International Workshop on Computer Science Logic (CSL 1999) (Lecture Notes in Computer Science (LNCS), Vol. 1683). Springer, 453–468. https://doi.org/10.1007/3-540-48168-0_32 Google Scholar
Cross Ref
- Nathanael Arkor and Marcelo Fiore. 2020. Algebraic Models of Simple Type Theories: A Polynomial Approach. In Proceedings of the 35th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2020) (LICS ’20). ACM Press, 88–101. https://doi.org/10.1145/3373718.3394771 Google Scholar
Digital Library
- Brian Aydemir, Aaron Bohannon, Matthew Fairbairn, J. Nathan Foster, Benjamin C. Pierce, Peter Sewell, Dimitrios Vytiniotis, Geoffrey Washburn, Stephanie Weirich, and Steve Zdancewic. 2005. Mechanized Metatheory for the Masses: The PoplMark Challenge. In Proceedings of the 18th International Conference on Theorem Proving in Higher Order Logics (TPHOLs 2005). Springer, 50–65. https://doi.org/10.1007/11541868_4 Google Scholar
Digital Library
- Brian Aydemir, Arthur Charguéraud, Benjamin C. Pierce, Randy Pollack, and Stephanie Weirich. 2008. Engineering Formal Metatheory. ACM SIGPLAN Notices, 43, 1 (2008), 3–15. https://doi.org/10.1145/1328897.1328443 Google Scholar
Digital Library
- Henk P. Barendregt. 1984. The Lambda Calculus: Its Syntax and Semantics. Elsevier. https://doi.org/10.1016/c2009-0-14341-6 Google Scholar
Cross Ref
- Françoise Bellegarde and James Hook. 1994. Substitution: A Formal Methods Case Study Using Monads and Transformations. Science of Computer Programming, 23, 2-3 (1994), 287–311. https://doi.org/10.1016/0167-6423(94)00022-0 Google Scholar
Digital Library
- Nick Benton, Chung-Kil Hur, Andrew J Kennedy, and Conor McBride. 2012. Strongly typed term representations in Coq. Journal of Automated Reasoning, 49, 2 (2012), 141–159. https://doi.org/10.1007/s10817-011-9219-0 Google Scholar
Digital Library
- Richard S. Bird and Ross Paterson. 1999. De Bruijn Notation as a Nested Datatype. Journal of Functional Programming, 9, 1 (1999), 77–91. https://doi.org/10.1017/S0956796899003366 Google Scholar
Digital Library
- Jasmin Christian Blanchette, Lorenzo Gheri, Andrei Popescu, and Dmitriy Traytel. 2019. Bindings as Bounded Natural Functors. Proceedings of the ACM on Programming Languages, 3, POPL (2019), https://doi.org/10.1145/3290335 Google Scholar
Digital Library
- Peio Borthelle, Tom Hirschowitz, and Ambroise Lafont. 2020. A Cellular Howe Theorem. In Proceedings of the 35th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2020). ACM Press, 273–286. https://doi.org/10.1145/3373718.3394738 Google Scholar
Digital Library
- Arthur Charguéraud. 2012. The locally nameless representation. Journal of Automated Reasoning, 49, 3 (2012), 363–408. https://doi.org/10.1007/s10817-011-9225-2 Google Scholar
- Xiaohong Chen and Grigore Roşu. 2020. A General Approach to Define Binders Using Matching Logic. Proceedings of the ACM on Programming Languages, 4, ICFP (2020), https://doi.org/10.1145/3408970 Google Scholar
Digital Library
- Adam Chlipala. 2008. Parametric Higher-Order Abstract Syntax for Mechanized Semantics. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP ’08). Association for Computing Machinery, 143–156. https://doi.org/10.1145/1411204.1411226 Google Scholar
Digital Library
- Ernesto Copello, Nora Szasz, and Álvaro Tasistro. 2017. Formal metatheory of the Lambda calculus using Stoughton’s substitution. Theoretical Computer Science, 685 (2017), 65 – 82. https://doi.org/10.1016/j.tcs.2016.08.025 Google Scholar
Cross Ref
- Brian Day. 1970. On closed categories of functors. In Reports of the Midwest Category Seminar IV. Springer, 1–38.Google Scholar
- Gergő Érdi. 2018. Generic description of well-scoped, well-typed syntaxes. arxiv:1804.00119. arxiv:1804.00119Google Scholar
- Marcelo Fiore. 2006. On the structure of substitution. https://www.cl.cam.ac.uk/~mpf23/talks/MFPS2006.pdf Talk at MFPS 2006.Google Scholar
- Marcelo Fiore. 2008. Second-Order and Dependently-Sorted Abstract Syntax. In Proceedings of the 23rd Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2008). IEEE Computer Society, 57–68. https://doi.org/10.1109/LICS.2008.38 Google Scholar
Digital Library
- Marcelo Fiore. 2012. Discrete Generalised Polynomial Functors. In 39th International Colloquium on Automata, Languages and Programming (ICALP 2012) (Lecture Notes in Computer Science, Vol. 7392). Springer, 214–226. https://doi.org/10.1007/978-3-642-31585-5_22 Google Scholar
Digital Library
- Marcelo Fiore and Makoto Hamana. 2013. Multiversal Polymorphic Algebraic Theories: Syntax, Semantics, Translations, and Equational Logic. In Proceedings of the 28th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2013). IEEE Computer Society, 520–529. https://doi.org/10.1109/LICS.2013.59 Google Scholar
Cross Ref
- Marcelo Fiore and Chung-Kil Hur. 2010. Second-Order Equational Logic. In Proceedings of the 24th International Workshop on Computer Science Logic (CSL 2010), Anuj Dawar and Helmut Veith (Eds.) (Lecture Notes in Computer Science (LNCS), Vol. 6247). Springer, 320–335. https://doi.org/10.1007/978-3-642-15205-4_26 Google Scholar
Cross Ref
- Marcelo Fiore and Ola Mahmoud. 2010. Second-Order Algebraic Theories. In Proceedings of the 35th International Symposium on Mathematical Foundations of Computer Science (MFCS 2010), Petr Hliněný and Antonín Kučera (Eds.) (Lecture Notes in Computer Science (LNCS), Vol. 6281). Springer, 368–380. https://doi.org/10.1007/978-3-642-15155-2_33 Google Scholar
Cross Ref
- Marcelo Fiore, Gordon Plotkin, and Daniele Turi. 1999. Abstract Syntax and Variable Binding. In Proceedings of the 14th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 1999). IEEE Computer Society, 193–202. https://doi.org/10.1109/LICS.1999.782615 Google Scholar
Cross Ref
- Marcelo Fiore and Philip Saville. 2017. List Objects with Algebraic Structure. In Proceedings of the 2nd International Conference on Formal Structures for Computation and Deduction (FSCD 2017), Dale Miller (Ed.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 84). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 16:1–16:18. https://doi.org/10.4230/LIPIcs.FSCD.2017.16 Google Scholar
Cross Ref
- Murdoch J. Gabbay and Andrew M. Pitts. 1999. A New Approach to Abstract Syntax Involving Binders. In Proceedings of the 14th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 1999). IEEE Computer Society, 214–224. https://doi.org/10.1109/LICS.1999.782617 Google Scholar
Cross Ref
- Joseph A. Goguen, James W. Thatcher, and E. G. Wagner. 1976. An Initial Algebra Approach to the Specification, Correctness and Implementation of Abstract Data Types. IBM Research Report, 6487 (1976).Google Scholar
- Makoto Hamana. 2004. Free Σ -Monoids: A Higher-Order Syntax with Metavariables. In Proceedings of the Second Asian Symposium on Programming Languages and Systems (APLAS 2004), Wei-Ngan Chin (Ed.) (Lecture Notes in Computer Science (LNCS), Vol. 3302). Springer, 348–363. https://doi.org/10.1007/978-3-540-30477-7_23 Google Scholar
Cross Ref
- Martin Hofmann. 1999. Semantical Analysis of Higher-Order Abstract Syntax. Proceedings of the 14th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 1999), 204–213. https://doi.org/10.1109/lics.1999.782616 Google Scholar
Cross Ref
- Jason Hu and Jacques Carette. 2021. Formalizing category theory in Agda. In Proceedings of the 10th ACM SIGPLAN International Conference on Certified Programs and Proofs. 327–342. https://doi.org/10.1145/3437992.3439922 Google Scholar
Digital Library
- Martin Hyland and Christine Tasson. 2020. The linear-non-linear substitution 2-monad. arxiv:2005.09559. arxiv:2005.09559Google Scholar
- Jonas Kaiser, Steven Schäfer, and Kathrin Stark. 2018. Binder Aware Recursion over Well-Scoped de Bruijn Syntax. In Proceedings of the 7th ACM SIGPLAN Conference on Certified Programs and Proofs (CPP 2018). ACM Press, 293–306. https://doi.org/10.1145/3167098 Google Scholar
Digital Library
- Steven Keuchel, Stephanie Weirich, and Tom Schrijvers. 2016. Needle & Knot: Binder Boilerplate Tied Up. In Programming Languages and Systems, Peter Thiemann (Ed.). Springer Berlin Heidelberg, 419–445. https://doi.org/10.1007/978-3-662-49498-1_17 Google Scholar
Digital Library
- Anders Kock. 1971. Closed categories generated by commutative monads. Journal of the Australian Mathematical Society, 12, 4 (1971), 405–424. https://doi.org/10.1017/S1446788700010272 Google Scholar
Cross Ref
- Wen Kokke, Jeremy G. Siek, and Philip Wadler. 2020. Programming language foundations in Agda. Science of Computer Programming, 194 (2020), 102440. https://doi.org/10.1016/j.scico.2020.102440 Google Scholar
Cross Ref
- Joachim Lambek. 1980. From λ -calculus to cartesian closed categories. To HB Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, 375–402.Google Scholar
- Gyesik Lee, Bruno C. D. S. Oliveira, Sungkeun Cho, and Kwangkeun Yi. 2012. GMeta: A Generic Formal Metatheory Framework for First-Order Representations. In Programming Languages and Systems, Helmut Seidl (Ed.). Springer Berlin Heidelberg, 436–455. https://doi.org/10.1007/978-3-642-28869-2_22 Google Scholar
Digital Library
- The Coq Development Team. 2004. The Coq proof assistant reference manual. https://coq.inria.fr/distrib/current/files/CoqRefMan.pdfGoogle Scholar
- Conor McBride. 2005. Type-preserving renaming and substitution. http://strictlypositive.org/ren-sub.pdf Unpublished note.Google Scholar
- Conor McBride and James McKinna. 2004. Functional pearl: I am not a number – I am a free variable. In Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell. 1–9. https://doi.org/10.1145/1017472.1017477 Google Scholar
Digital Library
- Ulf Norell. 2009. Dependently Typed Programming in Agda. Proceedings of the 4th International Workshop on Types in Language Design and Implementation (TLDI 2009), 1–2. https://doi.org/10.1145/1481861.1481862 Google Scholar
Digital Library
- Frank Pfenning and Conal Elliot. 1988. Higher-order abstract syntax. Proceedings of the 9th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 1988), 199–208. https://doi.org/10.1145/960116.54010 Google Scholar
Digital Library
- Matthew Pickering, Gergő Érdi, Simon Peyton Jones, and Richard A. Eisenberg. 2016. Pattern Synonyms. In Proceedings of the 9th International Symposium on Haskell (Haskell 2016). Association for Computing Machinery, 80–91. https://doi.org/10.1145/2976002.2976013 Google Scholar
Digital Library
- Don Pigozzi and Antonino Salibra. 1995. The abstract variable-binding calculus. Studia Logica, 55, 1 (1995), 129–179. https://doi.org/10.1007/bf01053036 Google Scholar
Cross Ref
- Andrew M. Pitts. 2019. Initial algebra for a strictly positive endofunctor constructed using sized types and quotient types. https://www.cl.cam.ac.uk/~amp12/agda/initial-T-algebras/Google Scholar
- Gordon D. Plotkin. 2020. A Complete Equational Axiomatisation of Partial Differentiation. Electronic Notes in Theoretical Computer Science, 352 (2020), 211 – 232. https://doi.org/j.entcs.2020.09.011Google Scholar
Cross Ref
- Emmanuel Polonowski. 2013. Automatically Generated Infrastructure for De Bruijn Syntaxes. In Interactive Theorem Proving, Sandrine Blazy, Christine Paulin-Mohring, and David Pichardie (Eds.). Springer Berlin Heidelberg, 402–417. https://doi.org/10.1007/978-3-642-39634-2_29 Google Scholar
Digital Library
- Mark R. Shinwell, Andrew M. Pitts, and Murdoch J. Gabbay. 2003. FreshML: Programming with Binders Made Simple. In Proceedings of the 8th ACM SIGPLAN International Conference on Functional Programming (ICFP 2003). ACM Press, 263–274. https://doi.org/10.1145/944705.944729 Google Scholar
Digital Library
- Kathrin Stark, Steven Schäfer, and Jonas Kaiser. 2019. Autosubst 2: Reasoning with Multi-Sorted de Bruijn Terms and Vector Substitutions. In Proceedings of the 8th ACM SIGPLAN International Conference on Certified Programs and Proofs. 166–180.Google Scholar
Digital Library
- Ross Street. 2013. Skew-closed categories. Journal of Pure and Applied Algebra, 217, 6 (2013), 973 – 988. https://doi.org/10.1016/j.jpaa.2012.09.020 Google Scholar
Cross Ref
- Yong Sun. 1999. An algebraic generalization of Frege structures – binding algebras. Theoretical Computer Science, 211, 1 (1999), 189 – 232. https://doi.org/10.1016/S0304-3975(97)00170-9 Google Scholar
Digital Library
- Kornél Szlachányi. 2012. Skew-monoidal categories and bialgebroids. Advances in Mathematics, 231, 3 (2012), 1694 – 1730. https://doi.org/10.1016/j.aim.2012.06.027 Google Scholar
Cross Ref
- Miki Tanaka. 2000. Abstract Syntax and Variable Binding for Linear Binders. In Proceedings of the 25th International Symposium on Mathematical Foundations of Computer Science (MFCS 2000), Mogens Nielsen and Branislav Rovan (Eds.) (Lecture Notes in Computer Science (LNCS), Vol. 1893). Springer, 670–679. https://doi.org/10.1007/3-540-44612-5_62 Google Scholar
Cross Ref
- Christian Urban and Cezary Kaliszyk. 2011. General Bindings and Alpha-Equivalence in Nominal Isabelle. In Programming Languages and Systems, Gilles Barthe (Ed.). Springer Berlin Heidelberg, 480–500. https://doi.org/10.1007/978-3-642-19718-5_25 Google Scholar
Cross Ref
- Vladimir Voevodsky, Benedikt Ahrens, and Daniel Grayson. 2014. UniMath — a computer-checked library of univalent mathematics. https://github.com/UniMath/UniMathGoogle Scholar
- Jérôme Vouillon. 2011. A Solution to the PoplMark Challenge Based on de Bruijn Indices. Journal of Automated Reasoning, 49 (2011), 327–362. https://doi.org/10.1007/s10817-011-9230-5 Google Scholar
Cross Ref
- Stephanie Weirich, Brent A. Yorgey, and Tim Sheard. 2011. Binders Unbound. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming (ICFP ’11). Association for Computing Machinery, 333–345. https://doi.org/10.1145/2034773.2034818 Google Scholar
Digital Library
Index Terms
Formal metatheory of second-order abstract syntax
Recommendations
A New Approach to Abstract Syntax Involving Binders
LICS '99: Proceedings of the 14th Annual IEEE Symposium on Logic in Computer ScienceThe Fraenkel-Mostowski permutation model of set theory with atoms (FM-sets) can serve as the semantic basis of meta-logics for specifying and reasoning about formal systems involving name binding, alpha-conversion, capture avoiding substitution, and so ...
Higher-order abstract syntax in classical higher-order logic
LFMTP '09: Proceedings of the Fourth International Workshop on Logical Frameworks and Meta-Languages: Theory and PracticeHigher-Order Abstract Syntax, or HOAS, is a technique for using a higher-order logic as a metalanguage for an object language with binding operators. It avoids formalizing syntactic details related to variable binding. This paper gives an extension to ...
Parametric higher-order abstract syntax for mechanized semantics
ICFP '08We present parametric higher-order abstract syntax (PHOAS), a new approach to formalizing the syntax of programming languages in computer proof assistants based on type theory. Like higher-order abstract syntax (HOAS), PHOAS uses the meta language's ...






Comments