skip to main content
research-article
Open Access

Visitors unchained

Published:29 August 2017Publication History
Skip Abstract Section

Abstract

Traversing and transforming abstract syntax trees that involve name binding is notoriously difficult to do in a correct, concise, modular, customizable manner. We address this problem in the setting of OCaml, a functional programming language equipped with powerful object-oriented features. We use visitor classes as partial, composable descriptions of the operations that we wish to perform on abstract syntax trees. We introduce "visitors", a simple type-directed facility for generating visitor classes that have no knowledge of binding. Separately, we present "alphaLib", a library of small hand-written visitor classes, each of which knows about a specific binding construct, a specific representation of names, and/or a specific operation on abstract syntax trees. By combining these components, a wide range of operations can be defined. Multiple representations of names can be supported, as well as conversions between representations. Binding structure can be described either in a programmatic style, by writing visitor methods, or in a declarative style, via preprogrammed binding combinators.

References

  1. Guillaume Allais, James Chapman, Conor McBride, and James McKinna. 2017. Type-and-scope Safe Programs and Their Proofs . In Certified Programs and Proofs (CPP). 195–207.Google ScholarGoogle Scholar
  2. Brian Aydemir, Arthur Charguéraud, Benjamin C. Pierce, Randy Pollack, and Stephanie Weirich. 2008. Engineering Formal Metatheory . In Principles of Programming Languages (POPL). 3–15.Google ScholarGoogle Scholar
  3. Brian Aydemir and Stephanie Weirich. 2010. LNgen: Tool Support for Locally Nameless Representations . Technical Report MS-CIS-10-24. University of Pennsylvania Department of Computer and Information Science.Google ScholarGoogle Scholar
  4. Richard Bird and Lambert Meertens. 1998. Nested Datatypes . In Mathematics of Program Construction (MPC) (Lecture Notes in Computer Science), Vol. 1422. Springer, 52–67. Google ScholarGoogle ScholarCross RefCross Ref
  5. Richard 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
  6. James Cheney. 2005. Scrap your nameplate . In International Conference on Functional Programming (ICFP). 180–191. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Francisco Ferreira and Brigitte Pientka. 2017. Programs Using Syntax with First-Class Binders . In European Symposium on Programming (ESOP) (Lecture Notes in Computer Science), Vol. 10201. Springer, 504–529.Google ScholarGoogle ScholarCross RefCross Ref
  8. Cédric Fournet and Georges Gonthier. 1996. The Reflexive Chemical Abstract Machine and the Join-Calculus . In Principles of Programming Languages (POPL). 372–385. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Murdoch J. Gabbay and Andrew M. Pitts. 2002. A New Approach to Abstract Syntax with Variable Binding . Formal Aspects of Computing 13, 3–5 (2002), 341–363.Google ScholarGoogle ScholarCross RefCross Ref
  10. Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1995. Design Patterns: Elements of Reusable Object-oriented Software. Addison-Wesley.Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Jeremy Gibbons. 2006. Datatype-generic programming . In International Spring School on Datatype-Generic Programming (Lecture Notes in Computer Science), Vol. 4719. Springer, 1–71.Google ScholarGoogle Scholar
  12. Robert Harper, Furio Honsell, and Gordon D. Plotkin. 1993. A Framework for Defining Logics . Journal of the ACM 40, 1 (1993), 143–184. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Johan Jeuring, Sean Leather, José Pedro Magalhães, and Alexey Rodriguez Yakushev. 2008. Libraries for Generic Programming in Haskell . In Advanced Functional Programming (Lecture Notes in Computer Science), Vol. 5832. Springer, 165–229. Google ScholarGoogle ScholarCross RefCross Ref
  14. Steven Keuchel and Tom Schrijvers. 2015. InBound: simple yet powerful specification of syntax with binders . (2015). Unpublished.Google ScholarGoogle Scholar
  15. Steven Keuchel, Stephanie Weirich, and Tom Schrijvers. 2016. Needle & Knot: Binder Boilerplate Tied Up . In European Symposium on Programming (ESOP) (Lecture Notes in Computer Science), Vol. 9632. Springer, 419–445.Google ScholarGoogle Scholar
  16. Gabriël Konat, Lennart Kats, Guido Wachsmuth, and Eelco Visser. 2013. Declarative Name Binding and Scope Rules . In Software Language Engineering (Lecture Notes in Computer Science), Vol. 7745. Springer, 311–331. Google ScholarGoogle ScholarCross RefCross Ref
  17. Ralf Lämmel and Simon Peyton Jones. 2005. Scrap your boilerplate with class: extensible generic functions . In International Conference on Functional Programming (ICFP). 204–215. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Gyesik Lee, Bruno C. d. S. Oliveira, Sungkeun Cho, and Kwangkeun Yi. 2012. GMeta: A Generic Formal Metatheory Framework for First-Order Representations . In European Symposium on Programming (ESOP) (Lecture Notes in Computer Science), Vol. 7211. Springer, 436–455.Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier Rémy, and Jérôme Vouillon. 2016. The OCaml system: documentation and user’s manual . (2016).Google ScholarGoogle Scholar
  20. Dale Miller. 2000. Abstract Syntax for Variable Binders: An Overview . In Computational Logic (Lecture Notes in Computer Science), Vol. 1861. Springer, 239–253. Google ScholarGoogle ScholarCross RefCross Ref
  21. Yaron Minsky, Anil Madhavapeddy, and Jason Hickey. 2013. Real World OCaml: Functional programming for the masses . O’Reilly.Google ScholarGoogle Scholar
  22. Gopalan Nadathur and Dale Miller. 1988. An Overview of Lambda-Prolog . In Logic Programming. 810–827.Google ScholarGoogle Scholar
  23. Pierre Neron, Andrew P. Tolmach, Eelco Visser, and Guido Wachsmuth. 2015. A Theory of name resolution . In European Symposium on Programming (ESOP) (Lecture Notes in Computer Science), Vol. 9032. Springer, 205–231.Google ScholarGoogle ScholarCross RefCross Ref
  24. Simon Peyton Jones and Simon Marlow. 2002. Secrets of the Glasgow Haskell Compiler inliner . Journal of Functional Programming 12, 4&5 (2002), 393–433.Google ScholarGoogle Scholar
  25. Brigitte Pientka. 2008. A type-theoretic foundation for programming with higher-order abstract syntax and first-class substitutions . In Principles of Programming Languages (POPL). 371–382. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. François Pottier. 2006. An overview of C α ml . In ACM Workshop on ML (Electronic Notes in Theoretical Computer Science), Vol. 148. 27–52. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. François Pottier. 2017a. AlphaLib. https://gitlab.inria.fr/fpottier/alphalib . (2017).Google ScholarGoogle Scholar
  28. François Pottier. 2017b. The visitors package. https://gitlab.inria.fr/fpottier/visitors . (2017).Google ScholarGoogle Scholar
  29. Nicolas Pouillard and François Pottier. 2012. A unified treatment of syntax with binders . Journal of Functional Programming 22, 4–5 (2012), 614–704.Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Didier Rémy and Jérôme Vouillon. 1998. Objective ML: An effective object-oriented extension to ML . Theory and Practice of Object Systems 4, 1 (1998), 27–50. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Steven Schäfer, Tobias Tebbi, and Gert Smolka. 2015. Autosubst: Reasoning with de Bruijn Terms and Parallel Substitutions . In Interactive Theorem Proving (ITP) (Lecture Notes in Computer Science), Vol. 9236. Springer, 359–374. Google ScholarGoogle ScholarCross RefCross Ref
  32. Peter Sewell, Francesco Zappa Nardelli, Scott Owens, Gilles Peskine, Thomas Ridge, Susmit Sarkar, and Rok Strnisa. 2010. Ott: Effective tool support for the working semanticist . Journal of Functional Programming 20, 1 (2010), 71–122. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Mark R. Shinwell. 2006. Fresh O’Caml: nominal abstract syntax for the masses . Electronic Notes in Theoretical Computer Science 148, 2 (2006), 53–77. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Mark R. Shinwell, Andrew M. Pitts, and Murdoch J. Gabbay. 2003. FreshML: Programming with Binders Made Simple . In International Conference on Functional Programming (ICFP). 263–274. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Carolyn Talcott. 1993. A Theory of Binding Structures and Applications to Rewriting . Theoretical Computer Science 112, 1 (1993), 99–143. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Christian Urban. 2008. Nominal Techniques in Isabelle/HOL . Journal of Automated Reasoning 40, 4 (2008), 327–356. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Christian Urban, Andrew Pitts, and Murdoch Gabbay. 2004. Nominal Unification . Theoretical Computer Science 323 (2004), 473–497. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Stephanie Weirich. 2006. RepLib: a library for derivable type classes . In Haskell workshop. 1–12.Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Stephanie Weirich, Brent A. Yorgey, and Tim Sheard. 2011. Binders unbound . In International Conference on Functional Programming (ICFP). 333–345. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded Recursive Datatype Constructors . In Principles of Programming Languages (POPL). 224–235.Google ScholarGoogle Scholar
  41. Hongbo Zhang and Steve Zdancewic. 2013. Fan: compile-time metaprogramming for OCaml . (2013). Unpublished.Google ScholarGoogle Scholar

Index Terms

  1. Visitors unchained

      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!