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

Reasonably programmable literal notation

Published:30 July 2018Publication History
Skip Abstract Section

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”.

Skip Supplemental Material Section

Supplemental Material

a106-omar.webm

References

  1. Michael D. Adams. 2015. Towards the Essence of Hygiene. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle Scholar
  3. 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 ScholarGoogle Scholar
  4. Alan Bawden. 1999. Quasiquotation in Lisp. In Partial Evaluation and Semantic-Based Program Manipulation. http: //repository.readscheme.org/ftp/papers/pepm99/bawden.pdfGoogle ScholarGoogle Scholar
  5. Frédéric Bour, Thomas Refis, and Gabriel Scherer. 2018. Experience report: Merlin, a Language Server for OCaml. In ICFP.Google ScholarGoogle Scholar
  6. Martin Bravenboer, Eelco Dolstra, and Eelco Visser. 2007. Preventing Injection Attacks with Syntax Embeddings. In GPCE. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. Florian Cajori. 1928. A history of mathematical notations. Vol. 1. Courier Corporation.Google ScholarGoogle Scholar
  9. Adam Chlipala. 2010. Ur: statically-typed metaprogramming with type-level record computation. In PLDI. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Adam Chlipala. 2015. Ur/Web: A Simple Model for Programming the Web. In POPL. http://dl.acm.org/citation.cfm?id=2676726 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. William D. Clinger and Jonathan Rees. 1991. Macros That Work. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Ryan Culpepper and Matthias Felleisen. 2010. Debugging hygienic macros. Sci. Comput. Program. 75, 7 (2010), 496–515. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Ryan Culpepper, Scott Owens, and Matthew Flatt. 2005. Syntactic abstraction in component interfaces. In International Conference on Generative Programming and Component Engineering (GPCE). Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle Scholar
  15. Rowan Davies and Frank Pfenning. 1996. A Modal Analysis of Staged Computation. In POPL. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Daniel de Rauglaudre. 2003. Camlp4 reference manual. Online (September 2003) (2003).Google ScholarGoogle Scholar
  17. Stephen Dolan. 2018. Staged Metaprogramming in stock OCaml. https://github.com/stedolan/ppx_stage/ . Retrieved Mar. 14, 2018.Google ScholarGoogle Scholar
  18. R. Kent Dybvig, Robert Hieb, and Carl Bruggeman. 1992. Syntactic Abstraction in Scheme. Lisp and Symbolic Computation 5, 4 (1992), 295–326. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Sebastian Erdweg, Tillmann Rendel, Christian Kastner, and Klaus Ostermann. 2011. SugarJ: Library-based syntactic language extensibility. In OOPSLA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Sebastian Erdweg and Felix Rieger. 2013. A framework for extensible languages. In GPCE. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. Matthew Flatt. 2012. Creating Languages in Racket. Commun. ACM 55, 1 (Jan. 2012), 48–56. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle Scholar
  24. Steven Ganz, Amr Sabry, and Walid Taha. 2001. Macros as Multi-Stage Computations: Type-Safe, Generative, Binding Macros in MacroML. In ICFP. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 ScholarGoogle Scholar
  26. Susan L Graham, Charles B Haley, and William N Joy. 1979. Practical LR Error Recovery. Vol. 14. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. T.G. Griffin. 1988. Notational definition-a formal account. In Logic in Computer Science (LICS ’88). 372–383.Google ScholarGoogle Scholar
  29. Robert Harper. 1997. Programming in Standard ML. http://www.cs.cmu.edu/~rwh/smlbook/book.pdf . Working draft, retrieved June 21, 2015.Google ScholarGoogle Scholar
  30. Robert Harper. 2012. Practical Foundations for Programming Languages. Cambridge University Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. T. P. Hart. 1963. MACRO Definitions for LISP. Report A. I. MEMO 57. Massachusetts Institute of Technology, A.I. Lab., Cambridge, Massachusetts. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. David Herman. 2010. A Theory of Typed Hygienic Macros. Ph.D. Dissertation. Northeastern University, Boston, MA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. David Herman and Mitchell Wand. 2008. A Theory of Hygienic Macros. In ESOP. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. 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 ScholarGoogle ScholarCross RefCross Ref
  35. IEEE. 2016. Information Technology Portable Operating System Interface (POSIX) Base Specifications, Issue 7. (2016).Google ScholarGoogle Scholar
  36. Kenneth E. Iverson. 1980. Notation as a Tool of Thought. Commun. ACM 23, 8 (1980), 444–465. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Stephen C Johnson. 1975. Yacc: Yet another compiler-compiler. Vol. 32. Bell Laboratories Murray Hill, NJ.Google ScholarGoogle Scholar
  38. Simon Peyton Jones. 2003. Haskell 98 language and libraries: the revised report. Cambridge University Press.Google ScholarGoogle Scholar
  39. Simon Peyton Jones. 2013. New directions for Template Haskell. https://ghc.haskell.org/trac/ghc/blog/Template%20Haskell% 20Proposal . Retrieved Mar. 14, 2018.Google ScholarGoogle Scholar
  40. Jacques-Henri Jourdan, François Pottier, and Xavier Leroy. 2012. Validating LR (1) parsers. In European Symposium on Programming. Springer, 397–416. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Oleg Kiselyov. 2002. How to write seemingly unhygienic and referentially opaque macros with syntax-rules. In Scheme Workshop.Google ScholarGoogle Scholar
  42. 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 ScholarGoogle Scholar
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle Scholar
  45. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  46. Florian Lorenzen and Sebastian Erdweg. 2016. Sound type-dependent syntactic language extension. In POPL. http: //dl.acm.org/citation.cfm?id=2837614 Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Geoffrey Mainland. 2007. Why it’s nice to be quoted: quasiquoting for Haskell. In Haskell Workshop. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Coq Team. 2004. The Coq proof assistant reference manual. LogiCal Project. http://coq.inria.fr Version 8.0.Google ScholarGoogle Scholar
  49. J. McCarthy. 1978. History of LISP. In History of programming languages I. ACM, 173–185. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  51. Robin Milner, Mads Tofte, Robert Harper, and David MacQueen. 1997. The Definition of Standard ML (Revised). The MIT Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Stephan Albert Missura. 1997. Higher-Order Mixfix Syntax for Representing Mathematical Notation and its Parsing. Ph.D. Dissertation. ETH Zurich.Google ScholarGoogle Scholar
  53. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  54. U. Norell. 2007. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology (2007).Google ScholarGoogle Scholar
  55. Martin Odersky, Lex Spoon, and Bill Venners. 2008. Programming in Scala. Artima Inc.Google ScholarGoogle Scholar
  56. Cyrus Omar. 2017. Reasonably Programmable Syntax. Ph.D. Dissertation. Carnegie Mellon University.Google ScholarGoogle Scholar
  57. Cyrus Omar and Jonathan Aldrich. 2018. Reasonably Programmable Literal Notation: Supplemental Material. Technical Report CMU-ISR-18-104. Carnegie Mellon University.Google ScholarGoogle Scholar
  58. Cyrus Omar, Darya Kurilova, Ligia Nistor, Benjamin Chung, Alex Potanin, and Jonathan Aldrich. 2014. Safely Composable Type-Specific Languages. In ECOOP. Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  60. 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 ScholarGoogle Scholar
  61. Cyrus Omar, Chenglong Wang, and Jonathan Aldrich. 2015. Composable and Hygienic Typed Syntax Macros. In ACM Symposium on Applied Computing (SAC). Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  63. OWASP. 2017. OWASP Top 10 2013. https://www.owasp.org/index.php/Top_10_2017-Top_10 . Retrieved May 28, 2017.Google ScholarGoogle Scholar
  64. Benjamin C. Pierce and David N. Turner. 2000. Local Type Inference. ACM Trans. Program. Lang. Syst. 22, 1 (Jan. 2000), 1–44. Google ScholarGoogle ScholarDigital LibraryDigital Library
  65. Justin Pombrio and Shriram Krishnamurthi. 2018. Inferring type rules for syntactic sugar. In PLDI. ACM, 812–825. Google ScholarGoogle ScholarDigital LibraryDigital Library
  66. Justin Pombrio, Shriram Krishnamurthi, and Mitchell Wand. 2017. Inferring Scope through Syntactic Sugar. (2017).Google ScholarGoogle Scholar
  67. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  68. 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 ScholarGoogle Scholar
  69. Reason Team. 2018. Reason Guide: What and Why? https://reasonml.github.io/docs/en/what-and-why.html . Retrieved Mar. 14, 2018.Google ScholarGoogle Scholar
  70. J C Reynolds. 1983. Types, abstraction and parametric polymorphism. In IFIP Congress.Google ScholarGoogle Scholar
  71. Rust Team. 2018. Macros - Rust Documentation. https://doc.rust-lang.org/1.7.0/book/macros.html . Retrieved Mar. 30, 2018..Google ScholarGoogle Scholar
  72. August Schwerdfeger. 2010. Context-aware scanning and determinism-preserving grammar composition, in theory and practice. Ph.D. Dissertation. University of Minnesota. Google ScholarGoogle ScholarDigital LibraryDigital Library
  73. August Schwerdfeger and Eric Van Wyk. 2009. Verifiable composition of deterministic grammars. In PLDI. Google ScholarGoogle ScholarDigital LibraryDigital Library
  74. Denys Shabalin, Eugene Burmako, and Martin Odersky. 2013. Quasiquotes for Scala. Technical Report EPFL-REPORT-185242.Google ScholarGoogle Scholar
  75. Tim Sheard. 1999. Using MetaML: A Staged Programming Language. Lecture Notes in Computer Science 1608 (1999).Google ScholarGoogle Scholar
  76. Tim Sheard and Simon Peyton Jones. 2002. Template meta-programming for Haskell. In Haskell Workshop. Google ScholarGoogle ScholarDigital LibraryDigital Library
  77. Konrad Slind. 1991. Object language embedding in Standard ML of New-Jersey. In ICFP.Google ScholarGoogle Scholar
  78. SML/NJ Documentation. 2015. SML/NJ Quote/Antiquote. http://www.smlnj.org/doc/quote.html . Retrieved Nov. 3, 2015.Google ScholarGoogle Scholar
  79. Walid Taha. 2004. A gentle introduction to multi-stage programming. In Domain-Specific Program Generation. Springer, 30–50.Google ScholarGoogle Scholar
  80. Walid Taha and Patricia Johann. 2003. Staged Notational Definitions. In GPCE. Google ScholarGoogle ScholarDigital LibraryDigital Library
  81. Ken Thompson. 1968. Programming Techniques: Regular Expression Search Algorithm. Commun. ACM 11, 6 (June 1968), 419–422. Google ScholarGoogle ScholarDigital LibraryDigital Library
  82. Arie van Deursen, Paul Klint, and Frank Tip. 1993. Origin Tracking. J. Symb. Comput. (1993), 523–545. Google ScholarGoogle ScholarDigital LibraryDigital Library
  83. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  84. Jacob Wieland. 2009. Parsing Mixfix Expressions. Ph.D. Dissertation. Technische Universitat Berlin.Google ScholarGoogle Scholar

Index Terms

  1. Reasonably programmable literal notation

      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!