skip to main content
research-article
Open Access
Artifacts Available
Artifacts Evaluated & Functional

A type and scope safe universe of syntaxes with binding: their semantics and proofs

Published:30 July 2018Publication History
Skip Abstract Section

Abstract

Almost every programming language’s syntax 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, etc.), 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.

NB. we recommend printing the paper in colour to benefit from syntax highlighting in code fragments.

Skip Supplemental Material Section

Supplemental Material

a90-allais.webm

webm

109.1 MB

References

  1. Michael Abbott, Thorsten Altenkirch, Conor McBride, and Neil Ghani. 2005. ∂ for data: Differentiating data structures. Fundamenta Informaticae 65, 1-2 (2005), 1–28. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Andreas Abel. 2010. MiniAgda: Integrating Sized and Dependent Types. In Proceedings Workshop on Partiality and Recursion in Interactive Theorem Provers, PAR 2010, Edinburgh, UK, 15th July 2010. (EPTCS) , Ana Bove, Ekaterina Komendantskaya, and Milad Niqui (Eds.), Vol. 43. 14–28.Google ScholarGoogle ScholarCross RefCross Ref
  3. Andreas Abel, Alberto Momigliano, and Brigitte Pientka. 2017. POPLMark Reloaded. Proceedings of the Logical Frameworks and Meta-Languages: Theory and Practice Workshop (2017).Google ScholarGoogle Scholar
  4. Andreas Abel, Brigitte Pientka, David Thibodeau, and Anton Setzer. 2013. Copatterns: programming infinite structures by observations. In ACM SIGPLAN Notices, Vol. 48. ACM, 27–38. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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, 195–207. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Thorsten Altenkirch, James Chapman, and Tarmo Uustalu. 2010. Monads Need Not Be Endofunctors. Springer, 297–311. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Thorsten Altenkirch, James Chapman, and Tarmo Uustalu. 2014. Relative Monads Formalised. Journal of Formalized Reasoning 7, 1 (2014), 1–43.Google ScholarGoogle Scholar
  8. Thorsten Altenkirch, Martin Hofmann, and Thomas Streicher. 1995. Categorical reconstruction of a reduction free normalization proof. In LNCS, Vol. 530. Springer, 182–199. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Thorsten Altenkirch and Conor McBride. 2003. Generic Programming Within Dependently Typed Programming. In Proceedings of the IFIP TC2/WG2.1 Working Conference on Generic Programming . Kluwer, B.V., 1–20. http://dl.acm.org/ citation.cfm?id=647100.717294 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Thorsten Altenkirch and Bernhard Reus. 1999. Monadic presentations of lambda terms using generalized inductive types. In CSL. Springer, 453–468. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Robert Atkey. 2015. An Algebraic Approach to Typechecking and Elaboration. (2015). http://bentnib.org/posts/ 2015-04-19-algebraic-approach-typechecking-and-elaboration.htmlGoogle ScholarGoogle Scholar
  12. Brian E. 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 Theorem Proving in Higher Order Logics, Joe Hurd and Tom Melham (Eds.). Springer, 50–65. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Casper Bach Poulsen, Arjen Rouvoet, Andrew Tolmach, Robbert Krebbers, and Eelco Visser. 2018. Intrinsically-typed Definitional Interpreters for Imperative Languages. Proc. ACM Program. Lang. 2, POPL, Article 16 (Jan. 2018), 34 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Françoise Bellegarde and James Hook. 1994. Substitution: A formal methods case study using monads and transformations. Science of Computer Programming 23, 2 (1994), 287 – 311. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Marcin Benke, Peter Dybjer, and Patrik Jansson. 2003. Universes for Generic Programs and Proofs in Dependent Type Theory. Nordic J. of Computing 10, 4 (Dec. 2003), 265–289. http://dl.acm.org/citation.cfm?id=985799.985801 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Nick Benton, Chung-Kil Hur, Andrew J Kennedy, and Conor McBride. 2012. Strongly typed term representations in Coq. JAR 49, 2 (2012), 141–159. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Richard S. Bird and Ross Paterson. 1999. de Bruijn notation as a nested datatype. Journal of Functional Programming 9, 1 (1999), 77–91. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Edwin Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming 23, 5 (2013), 552–593.Google ScholarGoogle ScholarCross RefCross Ref
  19. James Chapman, Pierre-Évariste Dagand, Conor McBride, and Peter Morris. 2010. The Gentle Art of Levitation. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming (ICFP ’10) . ACM, 3–14. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. James Maitland Chapman. 2009. Type checking and normalisation. Ph.D. Dissertation. University of Nottingham (UK).Google ScholarGoogle Scholar
  21. Arthur Charguéraud. 2012. The Locally Nameless Representation. Journal of Automated Reasoning 49, 3 (01 Oct 2012), 363–408.Google ScholarGoogle ScholarCross RefCross Ref
  22. Adam Chlipala. 2008. Parametric higher-order abstract syntax for mechanized semantics. In ACM Sigplan Notices, Vol. 43. ACM, 143–156. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Ernesto Copello. 2017. On the Formalisation of the Metatheory of the Lambda Calculus and Languages with Binders. Ph.D. Dissertation. Universidad de la República (Uruguay).Google ScholarGoogle Scholar
  24. Catarina Coquand. 2002. A formalised proof of the soundness and completeness of a simply typed lambda-calculus with explicit substitutions. Higher-Order and Symbolic Computation 15, 1 (2002), 57–90. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Nicolaas Govert de Bruijn. 1972. Lambda Calculus Notation with Nameless Dummies. In Indagationes Mathematicae, Vol. 75. Elsevier, 381–392.Google ScholarGoogle Scholar
  26. Leonardo Mendonça de Moura, Soonho Kong, Jeremy Avigad, Floris van Doorn, and Jakob von Raumer. 2015. The Lean Theorem Prover (System Description). In Automated Deduction - CADE-25 - 25th International Conference on Automated Deduction, Berlin, Germany, August 1-7, 2015, Proceedings (Lecture Notes in Computer Science) , Amy P. Felty and Aart Middeldorp (Eds.), Vol. 9195. Springer, 378–388.Google ScholarGoogle ScholarCross RefCross Ref
  27. Peter Dybjer. 1994. Inductive families. Formal aspects of computing 6, 4 (1994), 440–465.Google ScholarGoogle Scholar
  28. Peter Dybjer and Anton Setzer. 1999. A Finite Axiomatization of Inductive-Recursive Definitions. Springer, 129–146. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Gergő Érdi. 2018. Generic description of well-scoped, well-typed syntaxes. (2018). https://github.com/gergoerdi/ universe-of-syntax Unpublished draft, privately communicated.Google ScholarGoogle Scholar
  30. Marcelo Fiore, Gordon Plotkin, and Daniele Turi. 1999. Abstract Syntax and Variable Binding (Extended Abstract). In Proc. 14 th LICS Conf. IEEE, Computer Society Press, 193–202. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Murdoch J. Gabbay and Andrew M. Pitts. 2001. A New Approach to Abstract Syntax with Variable Binding . 13, 3–5 (July 2001), 341–363. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Neil Ghani, Makoto Hamana, Tarmo Uustalu, and Varmo Vene. 2006. Representing cyclic structures as nested datatypes. In Proc. of 7th Symp. on Trends in Functional Programming, TFP , Vol. 2006.Google ScholarGoogle Scholar
  33. Makoto Hamana. 2009. Initial Algebra Semantics for Cyclic Sharing Structures. Springer, 127–141. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Paul Hudak. 1996. Building domain-specific embedded languages. ACM Computing Surveys (CSUR) 28, 4es (1996), 196. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Gérard Huet. 1997. The Zipper. Journal of Functional Programming 7, 5 (1997), 549–554. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Alan Jeffrey. 2011. Associativity for free! http://thread.gmane.org/gmane.comp.lang.agda/3259 . (2011).Google ScholarGoogle Scholar
  37. 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 International Conference on Certified Programs and Proofs (CPP 2018) . ACM, 293–306. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Andrew W. Keep and R. Kent Dybvig. 2013. A Nanopass Framework for Commercial Compiler Development. SIGPLAN Not. 48, 9 (Sept. 2013), 343–350. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Steven Keuchel, Stephanie Weirich, and Tom Schrijvers. 2016. Needle & Knot: Binder Boilerplate Tied Up. In Proceedings of the 25th European Symposium on Programming Languages and Systems - Volume 9632 . Springer-Verlag New York, Inc., 419–445.Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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, 436–455. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Per Martin-Löf. 1982. Constructive mathematics and computer programming. Studies in Logic and the Foundations of Mathematics 104 (1982), 153–175.Google ScholarGoogle ScholarCross RefCross Ref
  42. The Coq Development Team. 2017. The Coq proof assistant reference manual. π r 2 Team. http://coq.inria.fr Version 8.6.Google ScholarGoogle Scholar
  43. Conor McBride. 2017. Ornamental algebras, algebraic ornaments. (2017). https://personal.cis.strath.ac.uk/conor.mcbride/ pub/OAAO/Ornament.pdfGoogle ScholarGoogle Scholar
  44. Conor McBride and Ross Paterson. 2008. Applicative programming with effects. Journal of Functional Programming 18, 1 (2008), 1–13. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Craig McLaughlin, James McKinna, and Ian Stark. 2018. Triangulating Context Lemmas. In Proceedings of the 7th ACM SIGPLAN Conference on Certified Programs and Proofs (CPP 2018) . ACM, 102–114. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. John C Mitchell and Eugenio Moggi. 1991. Kripke-style models for typed lambda calculus. Annals of Pure and Applied Logic 51, 1-2 (1991), 99–124.Google ScholarGoogle ScholarCross RefCross Ref
  47. Peter Morris, Thorsten Altenkirch, and Conor McBride. 2006. Exploring the Regular Tree Types. In Types for Proofs and Programs , Jean-Christophe Filliâtre, Christine Paulin-Mohring, and Benjamin Werner (Eds.). Springer, 252–267. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Ulf Norell. 2009. Dependently typed programming in Agda. In AFP Summer School. Springer, 230–266. 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) . ACM, 80–91. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Benjamin C Pierce and David N Turner. 2000. Local type inference. ACM Transactions on Programming Languages and Systems (TOPLAS) 22, 1 (2000), 1–44. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Emmanuel Polonowski. 2013. Automatically Generated Infrastructure for De Bruijn Syntaxes. In Interactive Theorem Proving, Sandrine Blazy, Christine Paulin-Mohring, and David Pichardie (Eds.). Springer, 402–417. Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Wouter Swiestra. 2008. Data types à la carte. Journal of Functional Programming 18, 4 (2008), 423–436. Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. David Thibodeau, Alberto Momigliano, and Brigitte Pientka. 2016. A case-study in programming coinductive proofs: Howe’s method . Technical Report. Technical report, McGill University.Google ScholarGoogle Scholar

Index Terms

  1. A type and scope safe universe of syntaxes with binding: their semantics and proofs

      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