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.
- 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 Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Cross Ref
- Richard Bird and Ross Paterson. 1999. de Bruijn Notation as a Nested Datatype . Journal of Functional Programming 9, 1 (1999), 77–91. Google Scholar
Digital Library
- James Cheney. 2005. Scrap your nameplate . In International Conference on Functional Programming (ICFP). 180–191. Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1995. Design Patterns: Elements of Reusable Object-oriented Software. Addison-Wesley.Google Scholar
Digital Library
- 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 Scholar
- Robert Harper, Furio Honsell, and Gordon D. Plotkin. 1993. A Framework for Defining Logics . Journal of the ACM 40, 1 (1993), 143–184. Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- Steven Keuchel and Tom Schrijvers. 2015. InBound: simple yet powerful specification of syntax with binders . (2015). Unpublished.Google Scholar
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- Dale Miller. 2000. Abstract Syntax for Variable Binders: An Overview . In Computational Logic (Lecture Notes in Computer Science), Vol. 1861. Springer, 239–253. Google Scholar
Cross Ref
- Yaron Minsky, Anil Madhavapeddy, and Jason Hickey. 2013. Real World OCaml: Functional programming for the masses . O’Reilly.Google Scholar
- Gopalan Nadathur and Dale Miller. 1988. An Overview of Lambda-Prolog . In Logic Programming. 810–827.Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- François Pottier. 2017a. AlphaLib. https://gitlab.inria.fr/fpottier/alphalib . (2017).Google Scholar
- François Pottier. 2017b. The visitors package. https://gitlab.inria.fr/fpottier/visitors . (2017).Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Carolyn Talcott. 1993. A Theory of Binding Structures and Applications to Rewriting . Theoretical Computer Science 112, 1 (1993), 99–143. Google Scholar
Digital Library
- Christian Urban. 2008. Nominal Techniques in Isabelle/HOL . Journal of Automated Reasoning 40, 4 (2008), 327–356. Google Scholar
Digital Library
- Christian Urban, Andrew Pitts, and Murdoch Gabbay. 2004. Nominal Unification . Theoretical Computer Science 323 (2004), 473–497. Google Scholar
Digital Library
- Stephanie Weirich. 2006. RepLib: a library for derivable type classes . In Haskell workshop. 1–12.Google Scholar
Digital Library
- Stephanie Weirich, Brent A. Yorgey, and Tim Sheard. 2011. Binders unbound . In International Conference on Functional Programming (ICFP). 333–345. Google Scholar
Digital Library
- Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded Recursive Datatype Constructors . In Principles of Programming Languages (POPL). 224–235.Google Scholar
- Hongbo Zhang and Steve Zdancewic. 2013. Fan: compile-time metaprogramming for OCaml . (2013). Unpublished.Google Scholar
Index Terms
Visitors unchained
Recommendations
Fresh O'Caml: Nominal Abstract Syntax for the Masses
Nominal abstract syntax, as pioneered by the 'FreshML' series of metalanguages, provides first-order tools for the representation and manipulation of syntax involving bound names, binding operations and @a-equivalence. Fresh O'Caml fuses nominal ...
Scrap your nameplate: (functional pearl)
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingRecent research has shown how boilerplate code, or repetitive code for traversing datatypes, can be eliminated using generic programming techniques already available within some implementations of Haskell. One particularly intractable kind of ...
Scrap your nameplate: (functional pearl)
ICFP '05: Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingRecent research has shown how boilerplate code, or repetitive code for traversing datatypes, can be eliminated using generic programming techniques already available within some implementations of Haskell. One particularly intractable kind of ...






Comments