Abstract
General-purpose programming languages typically define literal notation for only a small number of common data structures, like lists. This is unsatisfying because there are many other data structures for which literal notation might be useful, e.g. finite maps, regular expressions, HTML elements, SQL queries, syntax trees for various languages and chemical structures. There may also be different implementations of each of these data structures behind a common interface that could all benefit from common literal notation. This paper introduces typed literal macros (TLMs), which allow library providers to define new literal notation of nearly arbitrary design at any specified type or parameterized family of types. Compared to existing approaches, TLMs are uniquely reasonable. TLM clients can reason abstractly, i.e. without examining grammars or generated expansions, about types and binding. The system only needs to convey to clients, via secondary notation, the inferred segmentation of each literal body, which gives the locations and types of spliced subterms. TLM providers can reason modularly about syntactic ambiguity and expansion correctness according to clear criteria. This paper incorporates TLMs into Reason, an emerging alternative front-end for OCaml, and demonstrates, through several non-trivial case studies, how TLMs integrate with the advanced features of OCaml, including pattern matching and the module system. We also discuss optional integration with MetaOCaml, which allows TLM providers to be more confident about type correctness. Finally, we establish these abstract reasoning principles formally with a detailed type-theoretic account of expression and pattern TLMs for “core ML”.
Supplemental Material
- Michael D. Adams. 2015. Towards the Essence of Hygiene. In POPL. Google Scholar
Digital Library
- Eric Anderson, Gilman D Veith, and David Weininger. 1987. SMILES, a line notation and computerized interpreter for chemical structures. US Environmental Protection Agency, Environmental Research Laboratory.Google Scholar
- Anton Bachin. 2018. Markup.ml — Error-recovering streaming HTML5 and XML parsers for OCaml. http://aantron.github. io/markup.ml/ . Retrieved Mar. 14, 2018.Google Scholar
- Alan Bawden. 1999. Quasiquotation in Lisp. In Partial Evaluation and Semantic-Based Program Manipulation. http: //repository.readscheme.org/ftp/papers/pepm99/bawden.pdfGoogle Scholar
- Frédéric Bour, Thomas Refis, and Gabriel Scherer. 2018. Experience report: Merlin, a Language Server for OCaml. In ICFP.Google Scholar
- Martin Bravenboer, Eelco Dolstra, and Eelco Visser. 2007. Preventing Injection Attacks with Syntax Embeddings. In GPCE. Google Scholar
Digital Library
- Eugene Burmako. 2013. Scala Macros: Let Our Powers Combine!: On How Rich Syntax and Static Types Work with Metaprogramming. In 4th Workshop on Scala. Article 3, 10 pages. Google Scholar
Digital Library
- Florian Cajori. 1928. A history of mathematical notations. Vol. 1. Courier Corporation.Google Scholar
- Adam Chlipala. 2010. Ur: statically-typed metaprogramming with type-level record computation. In PLDI. Google Scholar
Digital Library
- Adam Chlipala. 2015. Ur/Web: A Simple Model for Programming the Web. In POPL. http://dl.acm.org/citation.cfm?id=2676726 Google Scholar
Digital Library
- William D. Clinger and Jonathan Rees. 1991. Macros That Work. In POPL. Google Scholar
Digital Library
- Ryan Culpepper and Matthias Felleisen. 2010. Debugging hygienic macros. Sci. Comput. Program. 75, 7 (2010), 496–515. Google Scholar
Digital Library
- Ryan Culpepper, Scott Owens, and Matthew Flatt. 2005. Syntactic abstraction in component interfaces. In International Conference on Generative Programming and Component Engineering (GPCE). Google Scholar
Digital Library
- Nils Anders Danielsson and Ulf Norell. 2008. Parsing Mixfix Operators. In 20th International Symposium on Implementation and Application of Functional Languages (IFL) - Revised Selected Papers.Google Scholar
- Rowan Davies and Frank Pfenning. 1996. A Modal Analysis of Staged Computation. In POPL. Google Scholar
Digital Library
- Daniel de Rauglaudre. 2003. Camlp4 reference manual. Online (September 2003) (2003).Google Scholar
- Stephen Dolan. 2018. Staged Metaprogramming in stock OCaml. https://github.com/stedolan/ppx_stage/ . Retrieved Mar. 14, 2018.Google Scholar
- R. Kent Dybvig, Robert Hieb, and Carl Bruggeman. 1992. Syntactic Abstraction in Scheme. Lisp and Symbolic Computation 5, 4 (1992), 295–326. Google Scholar
Digital Library
- Sebastian Erdweg, Tillmann Rendel, Christian Kastner, and Klaus Ostermann. 2011. SugarJ: Library-based syntactic language extensibility. In OOPSLA. Google Scholar
Digital Library
- Sebastian Erdweg and Felix Rieger. 2013. A framework for extensible languages. In GPCE. Google Scholar
Digital Library
- Sebastian Erdweg, Felix Rieger, Tillmann Rendel, and Klaus Ostermann. 2012. Layout-sensitive language extensibility with SugarHaskell. In Proceedings of the 2012 Symposium on Haskell. ACM, 149–160. Google Scholar
Digital Library
- Matthew Flatt. 2012. Creating Languages in Racket. Commun. ACM 55, 1 (Jan. 2012), 48–56. Google Scholar
Digital Library
- Alain Frisch, Peter Zotov, and Gabriel Radanne. 2017. ppx_tools: Tools for authors of ppx rewriters. https://github.com/ ocaml-ppx/ppx_tools . Retrieved June 22, 2018.Google Scholar
- Steven Ganz, Amr Sabry, and Walid Taha. 2001. Macros as Multi-Stage Computations: Type-Safe, Generative, Binding Macros in MacroML. In ICFP. Google Scholar
Digital Library
- Saul Gorn. 1965. Explicit definitions and linguistic dominoes. In Systems and Computer Science, Proceedings of the Conference held at Univ. of Western Ontario. 77–115.Google Scholar
- Susan L Graham, Charles B Haley, and William N Joy. 1979. Practical LR Error Recovery. Vol. 14. ACM. Google Scholar
Digital Library
- T. R. G. Green. 1989. Cognitive Dimensions of Notations. In Proceedings of the HCI’89 Conference on People and Computers V (Cognitive Ergonomics). 443–460. Google Scholar
Digital Library
- T.G. Griffin. 1988. Notational definition-a formal account. In Logic in Computer Science (LICS ’88). 372–383.Google Scholar
- Robert Harper. 1997. Programming in Standard ML. http://www.cs.cmu.edu/~rwh/smlbook/book.pdf . Working draft, retrieved June 21, 2015.Google Scholar
- Robert Harper. 2012. Practical Foundations for Programming Languages. Cambridge University Press. Google Scholar
Digital Library
- T. P. Hart. 1963. MACRO Definitions for LISP. Report A. I. MEMO 57. Massachusetts Institute of Technology, A.I. Lab., Cambridge, Massachusetts. Google Scholar
Digital Library
- David Herman. 2010. A Theory of Typed Hygienic Macros. Ph.D. Dissertation. Northeastern University, Boston, MA. Google Scholar
Digital Library
- David Herman and Mitchell Wand. 2008. A Theory of Hygienic Macros. In ESOP. Google Scholar
Digital Library
- Graham Hutton. 1992. Higher-order functions for parsing. Journal of Functional Programming 2, 3 (July 1992), 323–343. http://www.cs.nott.ac.uk/Department/Staff/gmh/parsing.psGoogle Scholar
Cross Ref
- IEEE. 2016. Information Technology Portable Operating System Interface (POSIX) Base Specifications, Issue 7. (2016).Google Scholar
- Kenneth E. Iverson. 1980. Notation as a Tool of Thought. Commun. ACM 23, 8 (1980), 444–465. Google Scholar
Digital Library
- Stephen C Johnson. 1975. Yacc: Yet another compiler-compiler. Vol. 32. Bell Laboratories Murray Hill, NJ.Google Scholar
- Simon Peyton Jones. 2003. Haskell 98 language and libraries: the revised report. Cambridge University Press.Google Scholar
- Simon Peyton Jones. 2013. New directions for Template Haskell. https://ghc.haskell.org/trac/ghc/blog/Template%20Haskell% 20Proposal . Retrieved Mar. 14, 2018.Google Scholar
- Jacques-Henri Jourdan, François Pottier, and Xavier Leroy. 2012. Validating LR (1) parsers. In European Symposium on Programming. Springer, 397–416. Google Scholar
Digital Library
- Oleg Kiselyov. 2002. How to write seemingly unhygienic and referentially opaque macros with syntax-rules. In Scheme Workshop.Google Scholar
- Oleg Kiselyov. 2014. The Design and Implementation of BER MetaOCaml - System Description. In Functional and Logic Programming - 12th International Symposium, FLOPS 2014, Kanazawa, Japan, June 4-6, 2014. Proceedings. 86–102.Google Scholar
- Eugene E. Kohlbecker, Daniel P. Friedman, Matthias Felleisen, and Bruce Duba. 1986. Hygienic Macro Expansion. In Symposium on LISP and Functional Programming. 151–161. Google Scholar
Digital Library
- Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier Rémy, and Jérôme Vouillon. 2014. The OCaml system release 4.02 Documentation and user’s manual. Institut National de Recherche en Informatique et en Automatique.Google Scholar
- Florian Lorenzen and Sebastian Erdweg. 2013. Modular and automated type-soundness verification for language extensions. In ICFP. 331–342. http://dl.acm.org/citation.cfm?id=2500365 Google Scholar
Digital Library
- Florian Lorenzen and Sebastian Erdweg. 2016. Sound type-dependent syntactic language extension. In POPL. http: //dl.acm.org/citation.cfm?id=2837614 Google Scholar
Digital Library
- Geoffrey Mainland. 2007. Why it’s nice to be quoted: quasiquoting for Haskell. In Haskell Workshop. Google Scholar
Digital Library
- Coq Team. 2004. The Coq proof assistant reference manual. LogiCal Project. http://coq.inria.fr Version 8.0.Google Scholar
- J. McCarthy. 1978. History of LISP. In History of programming languages I. ACM, 173–185. Google Scholar
Digital Library
- Erik Meijer, Brian Beckman, and Gavin Bierman. 2006. LINQ: reconciling object, relations and XML in the .NET framework. In Proceedings of the 2006 ACM SIGMOD International Conference on Management of Data. ACM. Google Scholar
Digital Library
- Robin Milner, Mads Tofte, Robert Harper, and David MacQueen. 1997. The Definition of Standard ML (Revised). The MIT Press. Google Scholar
Digital Library
- Stephan Albert Missura. 1997. Higher-Order Mixfix Syntax for Representing Mathematical Notation and its Parsing. Ph.D. Dissertation. ETH Zurich.Google Scholar
- John C Mitchell and Gordon D Plotkin. 1988. Abstract types have existential type. ACM Transactions on Programming Languages and Systems (TOPLAS) 10, 3 (1988), 470–502. Google Scholar
Digital Library
- U. Norell. 2007. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology (2007).Google Scholar
- Martin Odersky, Lex Spoon, and Bill Venners. 2008. Programming in Scala. Artima Inc.Google Scholar
- Cyrus Omar. 2017. Reasonably Programmable Syntax. Ph.D. Dissertation. Carnegie Mellon University.Google Scholar
- Cyrus Omar and Jonathan Aldrich. 2018. Reasonably Programmable Literal Notation: Supplemental Material. Technical Report CMU-ISR-18-104. Carnegie Mellon University.Google Scholar
- Cyrus Omar, Darya Kurilova, Ligia Nistor, Benjamin Chung, Alex Potanin, and Jonathan Aldrich. 2014. Safely Composable Type-Specific Languages. In ECOOP. Google Scholar
Digital Library
- Cyrus Omar, Ian Voysey, Michael Hilton, Jonathan Aldrich, and Matthew A. Hammer. 2017a. Hazelnut: a bidirectionally typed structure editor calculus. In POPL. http://dl.acm.org/citation.cfm?id=3009900 Google Scholar
Digital Library
- Cyrus Omar, Ian Voysey, Michael Hilton, Joshua Sunshine, Claire Le Goues, Jonathan Aldrich, and Matthew A. Hammer. 2017b. Toward semantic foundations for program editors. In Symposium on Advances in Programming Languages (SNAPL). http://arxiv.org/abs/1703.08694Google Scholar
- Cyrus Omar, Chenglong Wang, and Jonathan Aldrich. 2015. Composable and Hygienic Typed Syntax Macros. In ACM Symposium on Applied Computing (SAC). Google Scholar
Digital Library
- Cyrus Omar, YoungSeok Yoon, Thomas D. LaToza, and Brad A. Myers. 2012. Active Code Completion. In International Conference on Software Engineering (ICSE). http://dl.acm.org/citation.cfm?id=2337223.2337324 Google Scholar
Digital Library
- OWASP. 2017. OWASP Top 10 2013. https://www.owasp.org/index.php/Top_10_2017-Top_10 . Retrieved May 28, 2017.Google Scholar
- Benjamin C. Pierce and David N. Turner. 2000. Local Type Inference. ACM Trans. Program. Lang. Syst. 22, 1 (Jan. 2000), 1–44. Google Scholar
Digital Library
- Justin Pombrio and Shriram Krishnamurthi. 2018. Inferring type rules for syntactic sugar. In PLDI. ACM, 812–825. Google Scholar
Digital Library
- Justin Pombrio, Shriram Krishnamurthi, and Mitchell Wand. 2017. Inferring Scope through Syntactic Sugar. (2017).Google Scholar
- François Pottier and Yann Régis-Gianas. 2006. Towards Efficient, Typed LR Parsers. Electr. Notes Theor. Comput. Sci. 148, 2 (2006), 155–180. Google Scholar
Digital Library
- François Pottier and Yann Régis-Gianas. 2016. The Menhir parser generator. http://gallium.inria.fr/fpottier/menhir . Retrieved Mar. 14, 2018. (2016).Google Scholar
- Reason Team. 2018. Reason Guide: What and Why? https://reasonml.github.io/docs/en/what-and-why.html . Retrieved Mar. 14, 2018.Google Scholar
- J C Reynolds. 1983. Types, abstraction and parametric polymorphism. In IFIP Congress.Google Scholar
- Rust Team. 2018. Macros - Rust Documentation. https://doc.rust-lang.org/1.7.0/book/macros.html . Retrieved Mar. 30, 2018..Google Scholar
- August Schwerdfeger. 2010. Context-aware scanning and determinism-preserving grammar composition, in theory and practice. Ph.D. Dissertation. University of Minnesota. Google Scholar
Digital Library
- August Schwerdfeger and Eric Van Wyk. 2009. Verifiable composition of deterministic grammars. In PLDI. Google Scholar
Digital Library
- Denys Shabalin, Eugene Burmako, and Martin Odersky. 2013. Quasiquotes for Scala. Technical Report EPFL-REPORT-185242.Google Scholar
- Tim Sheard. 1999. Using MetaML: A Staged Programming Language. Lecture Notes in Computer Science 1608 (1999).Google Scholar
- Tim Sheard and Simon Peyton Jones. 2002. Template meta-programming for Haskell. In Haskell Workshop. Google Scholar
Digital Library
- Konrad Slind. 1991. Object language embedding in Standard ML of New-Jersey. In ICFP.Google Scholar
- SML/NJ Documentation. 2015. SML/NJ Quote/Antiquote. http://www.smlnj.org/doc/quote.html . Retrieved Nov. 3, 2015.Google Scholar
- Walid Taha. 2004. A gentle introduction to multi-stage programming. In Domain-Specific Program Generation. Springer, 30–50.Google Scholar
- Walid Taha and Patricia Johann. 2003. Staged Notational Definitions. In GPCE. Google Scholar
Digital Library
- Ken Thompson. 1968. Programming Techniques: Regular Expression Search Algorithm. Commun. ACM 11, 6 (June 1968), 419–422. Google Scholar
Digital Library
- Arie van Deursen, Paul Klint, and Frank Tip. 1993. Origin Tracking. J. Symb. Comput. (1993), 523–545. Google Scholar
Digital Library
- Arthur Whitney and Dennis Shasha. 2001. Lots O’Ticks: Real Time High Performance Time Series Queries on Billions of Trades and Quotes. SIGMOD Rec. 30, 2 (May 2001), 617–617. Google Scholar
Digital Library
- Jacob Wieland. 2009. Parsing Mixfix Expressions. Ph.D. Dissertation. Technische Universitat Berlin.Google Scholar
Index Terms
Reasonably programmable literal notation
Recommendations
A Survey of Metaprogramming Languages
Metaprogramming is the process of writing computer programs that treat programs as data, enabling them to analyze or transform existing programs or generate new ones. While the concept of metaprogramming has existed for several decades, activities ...
Macros for domain-specific languages
Macros provide a powerful means of extending languages. They have proven useful in both general-purpose and domain-specific programming contexts. This paper presents an architecture for implementing macro-extensible DSLs on top of macro-extensible host ...
Safely Composable Type-Specific Languages
Proceedings of the 28th European Conference on ECOOP 2014 --- Object-Oriented Programming - Volume 8586Programming languages often include specialized syntax for common datatypes e.g. lists and some also build in support for specific specialized datatypes e.g. regular expressions, but user-defined types must use general-purpose syntax. Frustration with ...






Comments