skip to main content

Compositional embeddings of domain-specific languages

Published:31 October 2022Publication History
Skip Abstract Section

Abstract

A common approach to defining domain-specific languages (DSLs) is via a direct embedding into a host language. There are several well-known techniques to do such embeddings, including shallow and deep embeddings. However, such embeddings come with various trade-offs in existing programming languages. Owing to such trade-offs, many embedded DSLs end up using a mix of approaches in practice, requiring a substantial amount of code, as well as some advanced coding techniques.

In this paper, we show that the recently proposed Compositional Programming paradigm and the CP language provide improved support for embedded DSLs. In CP we obtain a new form of embedding, which we call a compositional embedding, that has most of the advantages of both shallow and deep embeddings. On the one hand, compositional embeddings enable various forms of linguistic reuse that are characteristic of shallow embeddings, including the ability to reuse host-language optimizations in the DSL and add new DSL constructs easily. On the other hand, similarly to deep embeddings, compositional embeddings support definitions by pattern matching or dynamic dispatching (including dependent interpretations, transformations, and optimizations) over the abstract syntax of the DSL and have the ability to add new interpretations. We illustrate an instance of compositional embeddings with a DSL for document authoring called ExT. The DSL is highly flexible and extensible, allowing users to create various non-trivial extensions easily. For instance, ExT supports various extensions that enable the production of wiki-like documents, LaTeX documents, vector graphics or charts. The viability of compositional embeddings for ExT is evaluated with three applications.

Skip Supplemental Material Section

Supplemental Material

References

  1. Dean Allen. 2002. Textile Markup Language Documentation. https://textile-lang.com Google ScholarGoogle Scholar
  2. Sven Apel, Don Batory, Christian Kästner, and Gunter Saake. 2013. Feature-Oriented Software Product Lines: Concepts and Implementation. Springer-Verlag. https://doi.org/10.1007/978-3-642-37521-7 Google ScholarGoogle ScholarCross RefCross Ref
  3. Michael Ballantyne, Alexis King, and Matthias Felleisen. 2020. Macros for Domain-Specific Languages. In OOPSLA. https://doi.org/10.1145/3428297 Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Xuan Bi and Bruno C. d. S. Oliveira. 2018. Typed First-Class Traits. In ECOOP. https://doi.org/10.4230/LIPIcs.ECOOP.2018.9 Google ScholarGoogle ScholarCross RefCross Ref
  5. Xuan Bi, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2018. The Essence of Nested Composition. In ECOOP. https://doi.org/10.4230/LIPIcs.ECOOP.2018.22 Google ScholarGoogle ScholarCross RefCross Ref
  6. Xuan Bi, Ningning Xie, Bruno C. d. S. Oliveira, and Tom Schrijvers. 2019. Distributive Disjoint Polymorphism for Compositional Programming. In ESOP. https://doi.org/10.1007/978-3-030-17184-1_14 Google ScholarGoogle ScholarCross RefCross Ref
  7. Richard Boulton, Andrew Gordon, Mike Gordon, John Harrison, John Herbert, and John Van Tassel. 1992. Experience with Embedding Hardware Description Languages in HOL. In TPCD. Google ScholarGoogle Scholar
  8. Jacques Carette, Oleg Kiselyov, and Chung-chieh Shan. 2009. Finally Tagless, Partially Evaluated: Tagless Staged Interpreters for Simpler Typed Languages. J. Funct. Program., 19, 5 (2009), https://doi.org/10.1017/S0956796809007205 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Koen Claessen and John Hughes. 2000. QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs. In ICFP. https://doi.org/10.1145/351240.351266 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Stéphane Ducasse, Oscar Nierstrasz, Nathanael Schärli, Roel Wuyts, and Andrew P. Black. 2006. Traits: A Mechanism for Fine-grained Reuse. ACM Trans. Program. Lang. Syst., 28, 2 (2006), https://doi.org/10.1145/1119479.1119483 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Jana Dunfield. 2014. Elaborating Intersection and Union Types. J. Funct. Program., 24, 2–3 (2014), https://doi.org/10.1017/S0956796813000270 Google ScholarGoogle ScholarCross RefCross Ref
  12. Sven Efftinge and Markus Völter. 2006. oAW xText: A Framework for Textual DSLs. Google ScholarGoogle Scholar
  13. Burak Emir, Martin Odersky, and John Williams. 2007. Matching Objects with Patterns. In ECOOP. https://doi.org/10.1007/978-3-540-73589-2_14 Google ScholarGoogle ScholarCross RefCross Ref
  14. Sebastian Erdweg, Tijs van der Storm, Markus Völter, Laurence Tratt, Remi Bosman, William R. Cook, Albert Gerritsen, Angelo Hulshout, Steven Kelly, Alex Loh, Gabriël Konat, Pedro J. Molina, Martin Palatnik, Risto Pohjonen, Eugen Schindler, Klemens Schindler, Riccardo Solmi, Vlad Vergu, Eelco Visser, Kevin van der Vlist, Guido Wachsmuth, and Jimi van der Woning. 2015. Evaluating and Comparing Language Workbenches: Existing Results and Benchmarks for the Future. Comput. Lang. Syst. Struct., 44 (2015), https://doi.org/10.1016/j.cl.2015.08.007 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Erik Ernst. 2001. Family Polymorphism. In ECOOP. https://doi.org/10.1007/3-540-45337-7_17 Google ScholarGoogle ScholarCross RefCross Ref
  16. Erik Ernst, Klaus Ostermann, and William R. Cook. 2006. A Virtual Class Calculus. In POPL. https://doi.org/10.1145/1111037.1111062 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Matthew Flatt and Eli Barzilay. 2009. Low-Level Scribble API: Structures And Processing. https://docs.racket-lang.org/scribble/core.html Google ScholarGoogle Scholar
  18. Matthew Flatt, Eli Barzilay, and Robert Bruce Findler. 2009. Scribble: Closing the Book on Ad Hoc Documentation Tools. In ICFP. https://doi.org/10.1145/1596550.1596569 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Martin Fowler. 2005. A Language Workbench in Action - MPS. https://martinfowler.com/articles/mpsAgree.html Google ScholarGoogle Scholar
  20. Martin Fowler. 2005. Language Workbenches: The Killer-App for Domain Specific Languages? https://martinfowler.com/articles/languageWorkbench.html Google ScholarGoogle Scholar
  21. Erick Gallesio and Manuel Serrano. 2005. Skribe: a Functional Authoring Language. J. Funct. Program., 15, 5 (2005), https://doi.org/10.1017/S0956796805005575 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1995. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Professional. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Jeremy Gibbons and Nicolas Wu. 2014. Folding Domain-Specific Languages: Deep and Shallow Embeddings (Functional Pearl). In ICFP. https://doi.org/10.1145/2628136.2628138 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Andy Gill. 2009. Type-Safe Observable Sharing in Haskell. In [email protected]. https://doi.org/10.1145/1596638.1596653 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. David Goodger. 2002. reStructuredText: Markup Syntax and Parser Component of Docutils. https://docutils.sourceforge.io/rst.html Google ScholarGoogle Scholar
  26. Seyed Hossein Haeri and Paul Keir. 2019. Solving the Expression Problem in C++, à la LMS. In ICTAC. https://doi.org/10.1007/978-3-030-32505-3_20 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Seyed Hossein Haeri and Sibylle Schupp. 2016. Expression Compatibility Problem. In SCSS. https://doi.org/10.29007/xlbn Google ScholarGoogle ScholarCross RefCross Ref
  28. Ralf Hinze. 2006. Generics for the Masses. J. Funct. Program., 16, 4–5 (2006), https://doi.org/10.1017/S0956796806006022 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Christian Hofer and Klaus Ostermann. 2010. Modular Domain-Specific Language Components in Scala. In GPCE. https://doi.org/10.1145/1868294.1868307 Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Christian Hofer, Klaus Ostermann, Tillmann Rendel, and Adriaan Moors. 2008. Polymorphic Embedding of DSLs. In GPCE. https://doi.org/10.1145/1449913.1449935 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Paul Hudak. 1998. Modular Domain Specific Languages and Tools. In ICSR. https://doi.org/10.1109/ICSR.1998.685738 Google ScholarGoogle ScholarCross RefCross Ref
  32. John Hughes. 1995. The Design of a Pretty-printing Library. In AFP. https://doi.org/10.1007/3-540-59451-5_3 Google ScholarGoogle ScholarCross RefCross Ref
  33. Vojin Jovanović, Amir Shaikhha, Sandro Stucki, Vladimir Nikolaev, Christoph Koch, and Martin Odersky. 2014. Yin-Yang: Concealing the Deep Embedding of DSLs. In GPCE. https://doi.org/10.1145/2658761.2658771 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Lennart C. L. Kats and Eelco Visser. 2010. The Spoofax Language Workbench: Rules for Declarative Specification of Languages and IDEs. In OOPSLA. https://doi.org/10.1145/1869459.1869497 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Oleg Kiselyov. 2010. Typed Tagless Final Interpreters. In SSGIP. https://doi.org/10.1007/978-3-642-32202-0_3 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Oleg Kiselyov. 2011. Implementing Explicit and Finding Implicit Sharing in Embedded DSLs. In DSL. https://doi.org/10.4204/EPTCS.66.11 Google ScholarGoogle ScholarCross RefCross Ref
  37. Holger Krahn, Bernhard Rumpe, and Steven Völkel. 2010. MontiCore: a Framework for Compositional Development of Domain Specific Languages. Int. J. Softw. Tools Technol. Transf., 12, 5 (2010), https://doi.org/10.1007/S10009-010-0142-1 Google ScholarGoogle ScholarCross RefCross Ref
  38. Shriram Krishnamurthi. 2001. Linguistic Reuse. Ph. D. Dissertation. Rice University. Google ScholarGoogle Scholar
  39. Daan Leijen and Erik Meijer. 2001. Parsec: Direct Style Monadic Parser Combinators for the Real World. Google ScholarGoogle Scholar
  40. John MacFarlane. 2014. CommonMark Spec. https://spec.commonmark.org Google ScholarGoogle Scholar
  41. Ole Lehrmann Madsen and Birger Møller-Pedersen. 1989. Virtual Classes: A Powerful Mechanism in Object-Oriented Programming. In OOPSLA. https://doi.org/10.1145/74877.74919 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. MediaWiki. 2003. Wikitext. https://www.mediawiki.org/wiki/Wikitext Google ScholarGoogle Scholar
  43. MediaWiki. 2011. Parsoid. https://www.mediawiki.org/wiki/Parsoid Google ScholarGoogle Scholar
  44. Bruno C. d. S. Oliveira. 2009. Modular Visitor Components: A Practical Solution to the Expression Families Problem. In ECOOP. https://doi.org/10.1007/978-3-642-03013-0_13 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Bruno C. d. S. Oliveira and William R. Cook. 2012. Extensibility for the Masses: Practical Extensibility with Object Algebras. In ECOOP. https://doi.org/10.1007/978-3-642-31057-7_2 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Bruno C. d. S. Oliveira, Ralf Hinze, and Andres Löh. 2006. Extensible and Modular Generics for the Masses. In TFP. Google ScholarGoogle Scholar
  47. Bruno C. d. S. Oliveira and Andres Löh. 2013. Abstract Syntax Graphs for Domain Specific Languages. In [email protected]. https://doi.org/10.1145/2426890.2426909 Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Bruno C. d. S. Oliveira, Zhiyuan Shi, and João Alpuim. 2016. Disjoint Intersection Types. In ICFP. https://doi.org/10.1145/2951913.2951945 Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Bruno C. d. S. Oliveira, Tijs van der Storm, Alex Loh, and William R. Cook. 2013. Feature-Oriented Programming with Object Algebras. In ECOOP. https://doi.org/10.1007/978-3-642-39038-8_2 Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. 2006. Simple Unification-Based Type Inference for GADTs. In ICFP. https://doi.org/10.1145/1160074.1159811 Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Tiark Rompf, Nada Amin, Adriaan Moors, Philipp Haller, and Martin Odersky. 2012. Scala-Virtualized: Linguistic Reuse for Deep Embeddings. High. Order Symb. Comput., 25, 1 (2012), https://doi.org/10.1007/S10990-013-9096-9 Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Tiark Rompf and Martin Odersky. 2010. Lightweight Modular Staging: A Pragmatic Approach to Runtime Code Generation and Compiled DSLs. In GPCE. https://doi.org/10.1145/1868294.1868314 Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Maximilian Scherr and Shigeru Chiba. 2014. Implicit Staging of EDSL Expressions: A Bridge between Shallow and Deep Embedding. In ECOOP. https://doi.org/10.1007/978-3-662-44202-9_16 Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. Tim Sheard and Simon Peyton Jones. 2002. Template Meta-programming for Haskell. In [email protected]. https://doi.org/10.1145/581690.581691 Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Josef Svenningsson and Emil Axelsson. 2015. Combining Deep and Shallow Embedding of Domain-Specific Languages. Comput. Lang. Syst. Struct., 44 (2015), https://doi.org/10.1016/j.cl.2015.07.003 Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. Wouter Swierstra. 2008. Data Types à la Carte (Functional Pearl). J. Funct. Program., 18, 4 (2008), https://doi.org/10.1017/S0956796808006758 Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. Philip Wadler. 1998. The Expression Problem. Posted on the Java Genericity mailing list. https://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt Google ScholarGoogle Scholar
  58. Philip Wadler. 2003. A Prettier Printer. In The Fun of Programming. https://doi.org/10.1007/978-1-349-91518-7_11 Google ScholarGoogle ScholarCross RefCross Ref
  59. Weixin Zhang and Bruno C. d. S. Oliveira. 2017. EVF: An Extensible and Expressive Visitor Framework for Programming Language Reuse. In ECOOP. https://doi.org/10.4230/LIPIcs.ECOOP.2017.29 Google ScholarGoogle ScholarCross RefCross Ref
  60. Weixin Zhang and Bruno C. d. S. Oliveira. 2019. Shallow EDSLs and Object-Oriented Programming: Beyond Simple Compositionality. Art Sci. Eng. Program., 3, 3 (2019), https://doi.org/10.22152/programming-journal.org/2019/3/10 Google ScholarGoogle ScholarCross RefCross Ref
  61. Weixin Zhang and Bruno C. d. S. Oliveira. 2020. Castor: Programming with Extensible Generative Visitors. Sci. Comput. Program., 193 (2020), https://doi.org/10.1016/j.scico.2020.102449 Google ScholarGoogle ScholarCross RefCross Ref
  62. Weixin Zhang, Yaozhu Sun, and Bruno C. d. S. Oliveira. 2021. Compositional Programming. ACM Trans. Program. Lang. Syst., 43, 3 (2021), https://doi.org/10.1145/3460228 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Compositional embeddings of domain-specific languages

      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

      • Article Metrics

        • Downloads (Last 12 months)231
        • Downloads (Last 6 weeks)27

        Other Metrics

      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!