Compositional embeddings of domain-specific languages
Yaozhu Sun, Utkarsh Dhandhania, Bruno C. d. S. Oliveira
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 E X T. The DSL is highly flexible and extensible, allowing users to create various non-trivial extensions easily. For instance, E X T supports various extensions that enable the production of wiki-like documents, L A T E X documents, vector graphics or charts. The viability of compositional embeddings for E X T is evaluated with three applications.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
Lineage
Builds on1
Related papers
- A Core Calculus for Documents: Or, Lambda: The Ultimate DocumentWill Crichton, Shriram KrishnamurthiPOPL 2024 · 4 citations
- MimIR: An Extensible and Type-Safe Intermediate Representation for the DSL AgeRoland Leißa, Marcel Ullrich, Joachim Meyer, Sebastian HackPOPL 2025 · 1 citation
- Fluent APIs in Functional LanguagesOri Roth, Yossi GilOOPSLA 2023 · 3 citations
- Imperative Compositional Programming: Type Sound Distributive Intersection Subtyping with References via Bidirectional TypingWenjia Ye, Yaozhu Sun, Bruno C. d. S. OliveiraOOPSLA 2024 · 1 citation
- How Domain Experts Use an Embedded DSLLisa Rennels, Sarah E. ChasinsOOPSLA 2023 · 4 citations
