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.
Supplemental Material
Available for Download
Appendices of the paper.
- Dean Allen. 2002. Textile Markup Language Documentation. https://textile-lang.com
Google Scholar
- 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 Scholar
Cross Ref
- Michael Ballantyne, Alexis King, and Matthias Felleisen. 2020. Macros for Domain-Specific Languages. In OOPSLA. https://doi.org/10.1145/3428297
Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Jana Dunfield. 2014. Elaborating Intersection and Union Types. J. Funct. Program., 24, 2–3 (2014), https://doi.org/10.1017/S0956796813000270
Google Scholar
Cross Ref
- Sven Efftinge and Markus Völter. 2006. oAW xText: A Framework for Textual DSLs.
Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Erik Ernst. 2001. Family Polymorphism. In ECOOP. https://doi.org/10.1007/3-540-45337-7_17
Google Scholar
Cross Ref
- Erik Ernst, Klaus Ostermann, and William R. Cook. 2006. A Virtual Class Calculus. In POPL. https://doi.org/10.1145/1111037.1111062
Google Scholar
Digital Library
- Matthew Flatt and Eli Barzilay. 2009. Low-Level Scribble API: Structures And Processing. https://docs.racket-lang.org/scribble/core.html
Google Scholar
- 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 Scholar
Digital Library
- Martin Fowler. 2005. A Language Workbench in Action - MPS. https://martinfowler.com/articles/mpsAgree.html
Google Scholar
- Martin Fowler. 2005. Language Workbenches: The Killer-App for Domain Specific Languages? https://martinfowler.com/articles/languageWorkbench.html
Google Scholar
- Erick Gallesio and Manuel Serrano. 2005. Skribe: a Functional Authoring Language. J. Funct. Program., 15, 5 (2005), https://doi.org/10.1017/S0956796805005575
Google Scholar
Digital Library
- Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1995. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Professional.
Google Scholar
Digital Library
- 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 Scholar
Digital Library
- Andy Gill. 2009. Type-Safe Observable Sharing in Haskell. In [email protected]. https://doi.org/10.1145/1596638.1596653
Google Scholar
Digital Library
- David Goodger. 2002. reStructuredText: Markup Syntax and Parser Component of Docutils. https://docutils.sourceforge.io/rst.html
Google Scholar
- 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 Scholar
Digital Library
- Seyed Hossein Haeri and Sibylle Schupp. 2016. Expression Compatibility Problem. In SCSS. https://doi.org/10.29007/xlbn
Google Scholar
Cross Ref
- Ralf Hinze. 2006. Generics for the Masses. J. Funct. Program., 16, 4–5 (2006), https://doi.org/10.1017/S0956796806006022
Google Scholar
Digital Library
- Christian Hofer and Klaus Ostermann. 2010. Modular Domain-Specific Language Components in Scala. In GPCE. https://doi.org/10.1145/1868294.1868307
Google Scholar
Digital Library
- Christian Hofer, Klaus Ostermann, Tillmann Rendel, and Adriaan Moors. 2008. Polymorphic Embedding of DSLs. In GPCE. https://doi.org/10.1145/1449913.1449935
Google Scholar
Digital Library
- Paul Hudak. 1998. Modular Domain Specific Languages and Tools. In ICSR. https://doi.org/10.1109/ICSR.1998.685738
Google Scholar
Cross Ref
- John Hughes. 1995. The Design of a Pretty-printing Library. In AFP. https://doi.org/10.1007/3-540-59451-5_3
Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Oleg Kiselyov. 2010. Typed Tagless Final Interpreters. In SSGIP. https://doi.org/10.1007/978-3-642-32202-0_3
Google Scholar
Digital Library
- Oleg Kiselyov. 2011. Implementing Explicit and Finding Implicit Sharing in Embedded DSLs. In DSL. https://doi.org/10.4204/EPTCS.66.11
Google Scholar
Cross Ref
- 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 Scholar
Cross Ref
- Shriram Krishnamurthi. 2001. Linguistic Reuse. Ph. D. Dissertation. Rice University.
Google Scholar
- Daan Leijen and Erik Meijer. 2001. Parsec: Direct Style Monadic Parser Combinators for the Real World.
Google Scholar
- John MacFarlane. 2014. CommonMark Spec. https://spec.commonmark.org
Google Scholar
- 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 Scholar
Digital Library
- MediaWiki. 2003. Wikitext. https://www.mediawiki.org/wiki/Wikitext
Google Scholar
- MediaWiki. 2011. Parsoid. https://www.mediawiki.org/wiki/Parsoid
Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Bruno C. d. S. Oliveira, Ralf Hinze, and Andres Löh. 2006. Extensible and Modular Generics for the Masses. In TFP.
Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Tim Sheard and Simon Peyton Jones. 2002. Template Meta-programming for Haskell. In [email protected]. https://doi.org/10.1145/581690.581691
Google Scholar
Digital Library
- 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 Scholar
Digital Library
- Wouter Swierstra. 2008. Data Types à la Carte (Functional Pearl). J. Funct. Program., 18, 4 (2008), https://doi.org/10.1017/S0956796808006758
Google Scholar
Digital Library
- 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 Scholar
- Philip Wadler. 2003. A Prettier Printer. In The Fun of Programming. https://doi.org/10.1007/978-1-349-91518-7_11
Google Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
Index Terms
Compositional embeddings of domain-specific languages
Recommendations
Bootstrapping domain-specific meta-languages in language workbenches
GPCE 2016: Proceedings of the 2016 ACM SIGPLAN International Conference on Generative Programming: Concepts and ExperiencesIt is common practice to bootstrap compilers of programming languages. By using the compiled language to implement the compiler, compiler developers can code in their own high-level language and gain a large-scale test case. In this paper, we ...
Bootstrapping domain-specific meta-languages in language workbenches
GPCE '16It is common practice to bootstrap compilers of programming languages. By using the compiled language to implement the compiler, compiler developers can code in their own high-level language and gain a large-scale test case. In this paper, we ...
Domain-Specific languages in few steps: the neverlang approach
SC'12: Proceedings of the 11th international conference on Software CompositionOften an ad hoc programming language integrating features from different programming languages and paradigms represents the best choice to express a concise and clean solution to a problem. But, developing a programming language is not an easy task and ...






Comments