Hostname: page-component-76fb5796d-wq484 Total loading time: 0 Render date: 2024-04-27T20:12:19.265Z Has data issue: false hasContentIssue false

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

Part of: ICFP2018

Published online by Cambridge University Press:  19 October 2021

GUILLAUME ALLAIS
Affiliation:
University of St Andrews, St Andrews KY16 9AJ, UK (e-mail: guillaume.allais@ens-lyon.org)
ROBERT ATKEY
Affiliation:
University of Strathclyde, Glasgow G1 1XQ, UK (e-mail: robert.atkey@strath.ac.uk)
JAMES CHAPMAN
Affiliation:
Input Output HK Ltd., Edinburgh EH8 9BT, UK (e-mail: james.chapman@iohk.io)
CONOR MCBRIDE
Affiliation:
University of Strathclyde, Glasgow G1 1XQ, UK (e-mail: conor.mcbride@strath.ac.uk)
JAMES MCKINNA
Affiliation:
Heriot-Watt University, Edinburgh EH14 4AS, UK (e-mail: J.McKinna@hw.ac.uk)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

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.

Type
Research Article
Copyright
© The Author(s), 2021. Published by Cambridge University Press

References

Abbott, M. G., Altenkirch, T., McBride, C. & Ghani, N. (2005) δ for data: Differentiating data structures. Fundamenta Informaticae. 65(1-2), 128.Google Scholar
Abel, A. (2010) MiniAgda: Integrating Sized and Dependent Types. Proceedings Workshop on Partiality and Recursion in Interactive Theorem Provers, PAR 2010, Edinburgh, UK, 15th July 2010. pp. 14–28.CrossRefGoogle Scholar
Abel, A., Allais, G., Hameer, A., Pientka, B., Momigliano, A., Schäfer, S. & Stark, K. (2019) POPLMark reloaded: Mechanizing proofs by logical relations. Journal of Functional Programming. 29, e19.CrossRefGoogle Scholar
Abel, A., Momigliano, A. & Pientka, B. (2017) POPLMark Reloaded. Proceedings of the Logical Frameworks and Meta-Languages: Theory and Practice Workshop. Google Scholar
Abel, A., Pientka, B., Thibodeau, D. & Setzer, A. (2013) Copatterns: programming infinite structures by observations. ACM SIGPLAN Notices. ACM. pp. 2738.Google Scholar
Allais, G. (2018) agdarsec – Total parser combinators. JFLA 2018 Journées Francophones des Langages Applicatifs. Banyuls-sur-Mer, France. publié par les auteurs. pp. 45–59.Google Scholar
Allais, G., Chapman, J., McBride, C. & McKinna, J. (2017) Type-and-scope safe programs and their proofs. Proceedings of the 6th ACM SIGPLAN Conference on Certified Programs and Proofs. ACM. pp. 195–207.CrossRefGoogle Scholar
Altenkirch, T., Chapman, J. & Uustalu, T. (2014) Relative monads formalised. Journal of Formalized Reasoning. 7(1), 143.Google Scholar
Altenkirch, T., Chapman, J. & Uustalu, T. (2015) Monads need not be endofunctors. Logical Methods in Computer Science. 11(1).CrossRefGoogle Scholar
Altenkirch, T., Ghani, N., Hancock, P., McBride, C. & Morris, P. (2015) Indexed containers. Journal of Functional Programming. 25, e5.CrossRefGoogle Scholar
Altenkirch, T., Hofmann, M. & Streicher, T. (1995) Categorical reconstruction of a reduction free normalization proof. LNCS. Springer. pp. 182–199.CrossRefGoogle Scholar
Altenkirch, T. & McBride, C. (2002) Generic programming within dependently typed programming. Generic Programming, IFIP TC2/WG2.1 Working Conference on Generic Programming, July 11-12, 2002, Dagstuhl, Germany. Kluwer. pp. 1–20.Google Scholar
Altenkirch, T. & Reus, B. (1999) Monadic presentations of lambda terms using generalized inductive types. CSL. Springer. pp. 453–468.CrossRefGoogle Scholar
Appel, A. W. & Jim, T. (1997) Shrinking lambda expressions in linear time. Journal of Functional Programming. 7(5), 515540.CrossRefGoogle Scholar
Atkey, R. (2015) An algebraic approach to typechecking and elaboration. http://bentnib.org/posts/2015-04-19-algebraic-approach-typechecking-and-elaboration.html.Google Scholar
Atkey, R. & Wood, J. (2018) Context constrained computation. 3rd Workshop on Type-Driven Development (TyDe ’18), Extended Abstract.Google Scholar
Aydemir, B. E., Bohannon, A., Fairbairn, M., Foster, J. N., Pierce, B. C., Sewell, P., Vytiniotis, D., Washburn, G., Weirich, S. & Zdancewic, S. (2005) Mechanized Metatheory for the Masses: The POPLMark Challenge. Theorem Proving in Higher Order Logics. Springer. pp. 5065.CrossRefGoogle Scholar
Bach Poulsen, C., Rouvoet, A., Tolmach, A., Krebbers, R. & Visser, E. (2018) Intrinsically-typed definitional interpreters for imperative languages. Proc. ACM Program. Lang. 2(POPL), 16:1–16:34.CrossRefGoogle Scholar
Barber, A. (1996) Dual intuitionistic linear logic. Technical Report ECS-LFCS-96-347. LFCS, University of Edinburgh.Google Scholar
Bellegarde, F. & Hook, J. (1994) Substitution: A formal methods case study using monads and transformations. Science of Computer Programming. 23(2), 287311.CrossRefGoogle Scholar
Benke, M., Dybjer, P. & Jansson, P. (2003) Universes for generic programs and proofs in dependent type theory. Nordic Journal of Computing. 10(4), 265289.Google Scholar
Benton, N., Hur, C.-K., Kennedy, A. J. & McBride, C. (2012) Strongly typed term representations in Coq. Journal of Automated Reasoning. 49(2), 141159.CrossRefGoogle Scholar
Benton, P. N., Bierman, G. M., de Paiva, V. & Hyland, M. (1993) A term calculus for intuitionistic linear logic. Typed Lambda Calculi and Applications, International Conference on Typed Lambda Calculi and Applications, TLCA ’93, Utrecht, The Netherlands, March 16-18, 1993, Proceedings. Springer. pp. 75–90.CrossRefGoogle Scholar
Berger, U. (1993) Program extraction from normalization proofs. In TLCA. Springer. pp. 91–106.CrossRefGoogle Scholar
Berger, U. & Schwichtenberg, H. (1991) An inverse of the evaluation functional for typed λ-calculus. LICS. IEEE. pp. 203–211.CrossRefGoogle Scholar
Bird, R. S. & Paterson, R. (1999) De Bruijn notation as a nested datatype. Journal of Functional Programming. 9(1), 7791.CrossRefGoogle Scholar
Brady, E. (2013) Idris, a general-purpose dependently typed programming language: Design and implementation. Journal of Functional Programming. 23(5), 552593.CrossRefGoogle Scholar
Brady, E. & Hammond, K. (2006) A verified staged interpreter is a verified compiler. Generative Programming and Component Engineering, 5th International Conference, GPCE 2006, Portland, Oregon, USA, October 22-26, 2006, Proceedings. ACM. pp. 111–120.CrossRefGoogle Scholar
Brunel, A., Gaboardi, M., Mazza, D. & Zdancewic, S. (2014) A Core Quantitative Coeffect Calculus. Programming Languages and Systems - 23rd European Symposium on Programming, ESOP 2014. pp. 351–370.CrossRefGoogle Scholar
Chapman, J., Dagand, P.-E., McBride, C. & Morris, P. (2010) The gentle art of levitation. Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming. ACM. pp. 3–14.CrossRefGoogle Scholar
Chapman, J. M. (2009) Type checking and normalisation. Ph.D. thesis. University of Nottingham (UK).Google Scholar
Charguéraud, A. (2012) The locally nameless representation. Journal of Automated Reasoning. 49(3), 363408.CrossRefGoogle Scholar
Cheney, J. (2005) Toward a general theory of names: binding and scope. ACM SIGPLAN International Conference on Functional Programming, Workshop on Mechanized reasoning about languages with variable binding, MERLIN 2005, Tallinn, Estonia, September 30, 2005. ACM. pp. 33–40.CrossRefGoogle Scholar
Chlipala, A. (2008) Parametric higher-order abstract syntax for mechanized semantics. Proceeding of the 13th ACM SIGPLAN international conference on Functional programming, ICFP 2008, Victoria, BC, Canada, September 20-28, 2008. ACM. pp. 143–156.CrossRefGoogle Scholar
Copello, E. (2017) On the Formalisation of the Metatheory of the Lambda Calculus and Languages with Binders. Ph.D. thesis. Universidad de la República (Uruguay).Google Scholar
Coquand, C. (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), 5790.CrossRefGoogle Scholar
Coquand, T. & Dybjer, P. (1997) Intuitionistic model constructions and normalization proofs. MSCS. 7(01), 7594.Google Scholar
Cortiñas, C. T. & Swierstra, W. (2018) From algebra to abstract machine: a verified generic construction. Proceedings of the 3rd ACM SIGPLAN International Workshop on Type-Driven Development, TyDe@ICFP 2018, St. Louis, MO, USA, September 27, 2018. ACM. pp. 78–90.CrossRefGoogle Scholar
Dagand, P. (2013) A cosmology of datatypes : reusability and dependent types. Ph.D. thesis. University of Strathclyde, Glasgow, UK.Google Scholar
Dagand, P. & McBride, C. (2014) Transporting functions across ornaments. Journal of Functional Programming. 24(2-3), 316383.CrossRefGoogle Scholar
Danielsson, N. A. (2010) Total parser combinators. Proceeding of the 15th ACM SIGPLAN international conference on Functional programming, ICFP 2010, Baltimore, Maryland, USA, September 27-29, 2010. ACM. pp. 285–296.CrossRefGoogle Scholar
de Bruijn, N. G. (1972) Lambda Calculus notation with nameless dummies. Indagationes Mathematicae. Elsevier. pp. 381392.Google Scholar
de Moura, L. M., Kong, S., Avigad, J., van Doorn, F. & von Raumer, J. (2015) The Lean theorem prover (system description). Automated Deduction - CADE-25 - 25th International Conference on Automated Deduction, Berlin, Germany, August 1-7, 2015, Proceedings. Springer. pp. 378–388.CrossRefGoogle Scholar
Dunfield, J. & Pfenning, F. (2004) Tridirectional typechecking. Proceedings of the 31st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM. pp. 281–292.CrossRefGoogle Scholar
Dybjer, P. (1994) Inductive families. Formal Aspects of computing. 6(4), 440465.CrossRefGoogle Scholar
Dybjer, P. & Setzer, A. (1999) A finite axiomatization of inductive-recursive definitions. Typed Lambda Calculi and Applications, 4th International Conference, TLCA’99, L’Aquila, Italy, April 7-9, 1999, Proceedings. Springer. pp. 129–146.CrossRefGoogle Scholar
Eisenberg, R. A. (2020) Stitch: the sound type-indexed type checker (Functional Pearl). Proceedings of the 13th ACM SIGPLAN International Symposium on Haskell, Haskell@ICFP 2020, Virtual Event, USA, August 7, 2020. ACM. pp. 39–53.Google Scholar
Érdi, G. (2018) Generic description of well-scoped, well-typed syntaxes. CoRR. abs/1804.00119.Google Scholar
Fiore, M. P., Plotkin, G. D. & Turi, D. (1999) Abstract syntax and variable binding. 14th Annual IEEE Symposium on Logic in Computer Science, Trento, Italy, July 2-5, 1999. IEEE Computer Society. pp. 193–202.CrossRefGoogle Scholar
Gabbay, M. & Pitts, A. M. (2002) A new approach to abstract syntax with variable binding. Formal Aspects of Computing. 13(3-5), 341363.CrossRefGoogle Scholar
Ghani, N., Hamana, M., Uustalu, T. & Vene, V. (2006) Representing cyclic structures as nested datatypes. Proceedings of 7th Trends in Functional Programming, 2006. Intellect. pp. 173–188.Google Scholar
Ghica, D. R. & Smith, A. I. (2014) Bounded linear types in a resource semiring. Programming Languages and Systems - 23rd European Symposium on Programming, ESOP 2014. pp. 331–350.CrossRefGoogle Scholar
Gibbons, J. & d. S. Oliveira, B. C. (2009) The essence of the Iterator pattern. Journal of Functional Programming. 19(3-4), 377–402.CrossRefGoogle Scholar
Hamana, M. (2009) Initial algebra semantics for cyclic sharing structures. Typed Lambda Calculi and Applications, 9th International Conference, TLCA 2009, Brasilia, Brazil, July 1-3, 2009. Proceedings. Springer. pp. 127–141.CrossRefGoogle Scholar
Hatcliff, J. & Danvy, O. (1994) A generic account of continuation-passing styles. Proceedings of the 21st ACM SIGPLAN-SIGACT symposium on Principles of programming languages. ACM. pp. 458–471.CrossRefGoogle Scholar
Hedberg, M. (1998) A coherence theorem for Martin-Löf’s type theory. Journal of Functional Programming. 8(4), 413436.CrossRefGoogle Scholar
Hinze, R. & Peyton Jones, S. L. (2000) Derivable type classes. Electronic Notes in Theoretical Computer Science. 41(1), 535.CrossRefGoogle Scholar
Hirschowitz, A. & Maggesi, M. (2012) Nested abstract syntax in Coq. Journal of Automated Reasoning. 49(3), 409426.CrossRefGoogle Scholar
Hofmann, M. & Streicher, T. (1994) The groupoid model refutes uniqueness of identity proofs. Proceedings of the Ninth Annual Symposium on Logic in Computer Science (LICS ’94), Paris, France, July 4-7, 1994. IEEE Computer Society. pp. 208–212.CrossRefGoogle Scholar
Hudak, P. (1996) Building domain-specific embedded languages. ACM Computing Surveys (CSUR). 28(4es), 196.CrossRefGoogle Scholar
Huet, G. (1997) The zipper. Journal of Functional Programming. 7(5), 549554.CrossRefGoogle Scholar
Jander, P. (2019) Verifying Type-and-Scope Safe Program Transformations. Master’s thesis. University of Edinburgh.Google Scholar
Jeffrey, A. (2011) Associativity for free! http://thread.gmane.org/gmane.comp.lang.agda/3259.Google Scholar
Kaiser, J., Schäfer, S. & Stark, K. (2018) Binder aware recursion over well-scoped de Bruijn syntax. Proceedings of the 7th ACM SIGPLAN International Conference on Certified Programs and Proofs. ACM. pp. 293–306.CrossRefGoogle Scholar
Keep, A. W. & Dybvig, R. K. (2013) A nanopass framework for commercial compiler development. SIGPLAN Not. 48(9), 343350.CrossRefGoogle Scholar
Keuchel, S. (2011 ) Generic Programming With Binders and Scope. Master’s thesis. Utrecht University.Google Scholar
Keuchel, S. & Jeuring, J. (2012) Generic conversions of abstract syntax representations. Proceedings of the 8th ACM SIGPLAN workshop on Generic programming, WGP@ICFP 2012, Copenhagen, Denmark, September 9-15, 2012. ACM. pp. 57–68.CrossRefGoogle Scholar
Keuchel, S., Weirich, S. & Schrijvers, T. (2016) Needle & Knot: Binder boilerplate tied up. Proceedings of the 25th European Symposium on Programming Languages and Systems - Volume 9632. Springer-Verlag New York, Inc. pp. 419–445.Google Scholar
Lee, G., Oliveira, B. C. D. S., Cho, S. & Yi, K. (2012) GMeta: A generic formal metatheory framework for first-order representations. Programming Languages and Systems. Springer. pp. 436455.CrossRefGoogle Scholar
Licata, D. R., Shulman, M. & Riley, M. (2017) A fibrational framework for substructural and modal logics. 2nd International Conference on Formal Structures for Computation and Deduction, FSCD 2017, September 3-9, 2017, Oxford, UK. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik. pp. 25:1–25:22.Löh, A. & Magalhães, J. P. (2011) Generic programming with indexed functors. Proceedings of the seventh ACM SIGPLAN workshop on Generic programming, WGP@ICFP 2011, Tokyo, Japan, September 19-21, 2011. ACM. pp. 1–12.Google Scholar
Magalhães, J. P., Dijkstra, A., Jeuring, J. & Löh, A. (2010) A generic deriving mechanism for haskell. Proceedings of the 3rd ACM SIGPLAN Symposium on Haskell, Haskell 2010, Baltimore, MD, USA, 30 September 2010. ACM. pp. 37–48.CrossRefGoogle Scholar
Malcolm, G. (1990) Data structures and program transformation. Science of Computer Programming. 14(2-3), 255279.CrossRefGoogle Scholar
Martin-Löf, P. (1982) Constructive mathematics and computer programming. Studies in Logic and the Foundations of Mathematics. 104, 153175.CrossRefGoogle Scholar
The Coq Development Team. (2017) The Coq proof assistant reference manual. πr 2 Team. Version 8.6.Google Scholar
McBride, C. & McKinna, J. (2004) The view from the left. Journal of Functional Programming. 14(1), 69111.CrossRefGoogle Scholar
McBride, C. & Paterson, R. (2008) Applicative programming with effects. Journal of Functional Programming. 18(1), 113.CrossRefGoogle Scholar
McLaughlin, C., McKinna, J. & Stark, I. (2018) Triangulating context lemmas. Proceedings of the 7th ACM SIGPLAN Conference on Certified Programs and Proofs. ACM. pp. 102–114.CrossRefGoogle Scholar
Milner, R., Tofte, M. & Macqueen, D. (1997) The Definition of Standard ML. MIT Press. Cambridge, MA, USA.CrossRefGoogle Scholar
Mitchell, J. C. & Moggi, E. (1991) Kripke-style models for typed lambda calculus. Annals of Pure and Applied Logic. 51(1-2), 99–124.CrossRefGoogle Scholar
Moggi, E. (1991) Notions of computation and monads. Information and Computation. 93(1), 5592.CrossRefGoogle Scholar
Morris, P., Altenkirch, T. & McBride, C. (2006) Exploring the regular tree types. Types for Proofs and Programs. Springer. pp. 252267.CrossRefGoogle Scholar
Norell, U. (2009) Dependently typed programming in Agda. In AFP Summer School. Springer. pp. 230–266.CrossRefGoogle Scholar
O’Hearn, P. W. (2003) On bunched typing. Journal of Functional Programming. 13(4), 747796.CrossRefGoogle Scholar
Petricek, T., Orchard, D. A. & Mycroft, A. (2014) Coeffects: a calculus of context-dependent computation. Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, Gothenburg, Sweden, September 1-3, 2014. ACM. pp. 123–135.CrossRefGoogle Scholar
Pfenning, F. (2004) Lecture 17: Bidirectional type checking. 15-312: Foundations of Programming Languages.Google Scholar
Pierce, B. C. & Turner, D. N. (2000) Local type inference. ACM Transactions on Programming Languages and Systems (TOPLAS). 22(1), 144.CrossRefGoogle Scholar
Polonowski, E. (2013) Automatically generated infrastructure for de Bruijn syntaxes. Interactive Theorem Proving. Springer. pp. 402417.CrossRefGoogle Scholar
Stump, A. (2016) Verified Functional Programming in Agda . Association for Computing Machinery and Morgan & Claypool. New York, NY, USA.Google Scholar
Swiestra, W. (2008) Data types à la carte. Journal of Functional Programming. 18(4), 423436.Google Scholar
Thibodeau, D., Momigliano, A. & Pientka, B. (2016) A case-study in programming coinductive proofs: Howe’s method. Technical report. Technical report, McGill University.Google Scholar
Wadler, P. (1987) Views: A way for pattern matching to cohabit with data abstraction. Conference Record of the Fourteenth Annual ACM Symposium on Principles of Programming Languages, Munich, Germany, January 21-23, 1987. ACM Press. pp. 307–313.CrossRefGoogle Scholar
Wadler, P. (1990) Deforestation: Transforming programs to eliminate trees. Theoretical Computer Science. 73(2), 231248.CrossRefGoogle Scholar
Wadler, P. & Kokke, W. (2018) Programming Language Foundations in Agda. Available at http://plfa.inf.ed.ac.uk.CrossRefGoogle Scholar
Weirich, S., Yorgey, B. A. & Sheard, T. (2011) Binders unbound. Proceeding of the 16th ACM SIGPLAN international conference on Functional Programming, ICFP 2011, Tokyo, Japan, September 19-21, 2011. ACM. pp. 333–345.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.