skip to main content

Formal metatheory of second-order abstract syntax

Published:12 January 2022Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

5-minute presentation of our POPL accepted paper "Formal Metatheory of Second-Order Abstract Syntax", giving a high-level overview of the library and our main contributions.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. Andreas Abel. 2010. MiniAgda: Integrating Sized and Dependent Types. arxiv:1012.4896. arxiv:1012.4896Google ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarCross RefCross Ref
  4. Peter Aczel. 1978. A General Church–Rosser Theorem. http://www.ens-lyon.fr/LIP/REWRITING/MISC/AGeneralChurch-RosserTheorem.pdf Unpublished note.Google ScholarGoogle Scholar
  5. 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 ScholarGoogle ScholarCross RefCross Ref
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarCross RefCross Ref
  8. 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 ScholarGoogle ScholarCross RefCross Ref
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. Henk P. Barendregt. 1984. The Lambda Calculus: Its Syntax and Semantics. Elsevier. https://doi.org/10.1016/c2009-0-14341-6 Google ScholarGoogle ScholarCross RefCross Ref
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle Scholar
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarCross RefCross Ref
  22. Brian Day. 1970. On closed categories of functors. In Reports of the Midwest Category Seminar IV. Springer, 1–38.Google ScholarGoogle Scholar
  23. Gergő Érdi. 2018. Generic description of well-scoped, well-typed syntaxes. arxiv:1804.00119. arxiv:1804.00119Google ScholarGoogle Scholar
  24. Marcelo Fiore. 2006. On the structure of substitution. https://www.cl.cam.ac.uk/~mpf23/talks/MFPS2006.pdf Talk at MFPS 2006.Google ScholarGoogle Scholar
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarCross RefCross Ref
  28. 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 ScholarGoogle ScholarCross RefCross Ref
  29. 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 ScholarGoogle ScholarCross RefCross Ref
  30. 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 ScholarGoogle ScholarCross RefCross Ref
  31. 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 ScholarGoogle ScholarCross RefCross Ref
  32. 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 ScholarGoogle ScholarCross RefCross Ref
  33. 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 ScholarGoogle Scholar
  34. 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 ScholarGoogle ScholarCross RefCross Ref
  35. 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 ScholarGoogle ScholarCross RefCross Ref
  36. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  37. Martin Hyland and Christine Tasson. 2020. The linear-non-linear substitution 2-monad. arxiv:2005.09559. arxiv:2005.09559Google ScholarGoogle Scholar
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle ScholarCross RefCross Ref
  41. 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 ScholarGoogle ScholarCross RefCross Ref
  42. Joachim Lambek. 1980. From λ -calculus to cartesian closed categories. To HB Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, 375–402.Google ScholarGoogle Scholar
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. The Coq Development Team. 2004. The Coq proof assistant reference manual. https://coq.inria.fr/distrib/current/files/CoqRefMan.pdfGoogle ScholarGoogle Scholar
  45. Conor McBride. 2005. Type-preserving renaming and substitution. http://strictlypositive.org/ren-sub.pdf Unpublished note.Google ScholarGoogle Scholar
  46. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  47. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  48. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  49. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  50. 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 ScholarGoogle ScholarCross RefCross Ref
  51. 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 ScholarGoogle Scholar
  52. 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 ScholarGoogle ScholarCross RefCross Ref
  53. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  54. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  55. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  56. 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 ScholarGoogle ScholarCross RefCross Ref
  57. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  58. 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 ScholarGoogle ScholarCross RefCross Ref
  59. 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 ScholarGoogle ScholarCross RefCross Ref
  60. 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 ScholarGoogle ScholarCross RefCross Ref
  61. Vladimir Voevodsky, Benedikt Ahrens, and Daniel Grayson. 2014. UniMath — a computer-checked library of univalent mathematics. https://github.com/UniMath/UniMathGoogle ScholarGoogle Scholar
  62. 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 ScholarGoogle ScholarCross RefCross Ref
  63. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Formal metatheory of second-order abstract syntax

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader
          About Cookies On This Site

          We use cookies to ensure that we give you the best experience on our website.

          Learn more

          Got it!