dsl-embedding
Skill17 starsChanged 9 months agoApache-2.0View on GitHub
Implements DSL embedding in host languages. Use when: (1) Building embedded
In this repository98 other files it gives its agents.
- abstract-interpretation-engineSkill
- abstract-machineSkill
- acsl-annotation-assistantSkill
- actor-model-implementerSkill
- algebraic-effectsSkill
- alias-and-points-to-analysisSkill
- axiomatic-semanticsSkill
- bidirectional-type-checkingSkill
- bisimulation-checkerSkill
- capability-systemSkill
- closure-converterSkill
- common-subexpression-eliminatorSkill
- concurrency-verifierSkill
- constant-propagation-passSkill
- contextual-equivalenceSkill
- control-flow-analysisSkill
- coq-proof-assistantSkill
- cps-transformerSkill
- dafny-verifierSkill
- dataflow-analysis-frameworkSkill
- dead-code-eliminatorSkill
- defunctionalizationSkill
- denotational-semantics-builderSkill
- dependent-type-implementerSkill
- effect-handlers-implementerSkill
- effect-systemSkill
- effect-type-systemSkill
- escape-analysisSkill
- existential-typesSkill
- ffi-designerSkill
- fuzzer-generatorSkill
- gadt-implementerSkill
- garbage-collector-implementerSkill
- graalvm-truffle-implementerSkill
- gradual-typing-implementerSkill
- higher-order-abstract-syntaxSkill
- hoare-logic-verifierSkill
- incremental-computationSkill
- information-flow-analyzerSkill
- inline-expanderSkill
- interprocedural-analysisSkill
- invariant-generatorSkill
- jit-compiler-builderSkill
- lambda-calculus-interpreterSkill
- language-server-protocolSkill
- lean-proverSkill
- lexer-generatorSkill
- linear-type-implementerSkill
- liveness-analysisSkill
- llvm-backend-generatorSkill
- lock-free-data-structureSkill
- loop-optimizerSkill
- loop-termination-proverSkill
- macro-expanderSkill
- memory-allocatorSkill
- message-passing-systemSkill
- mlir-dialect-designerSkill
- model-checkerSkill
- module-systemSkill
- monad-transformerSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 165
Build interpreter(s): Run DSL programs
- Distinctive: line 210
For general-purpose code: Use host language directly
- Distinctive: line 217
Type checking: Must implement
- Distinctive: line 227
Distribution: Must ship host language
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Domain-Specific Language (DSL) Embedding
Role Definition
You are a DSL embedding expert specializing in embedding domain-specific languages within host languages. You understand shallow vs deep embeddings, monadic DSLs, combinator libraries, and the engineering tradeoffs of external vs embedded DSLs.
Core Expertise
Theoretical Foundation
- Shallow embedding: Direct semantics in host language
- Deep embedding: Explicit AST representation
- Free monads: DSL as monad
- Finally tagless: Type-preserving embeddings
- Bootstrapping: Self-embedded languages
Technical Skills
Embedding Strategies
1. Shallow Embedding
-- DSL terms ARE host language values
type Expr a = a -- just use host functions
-- Example: arithmetic DSL
add :: Num a => a -> a -> a
add = (+)
mul :: Num a => a -> a -> a
mul = (*)
-- Usage is direct
example = mul (add 1 2) 3 -- = 92. Deep Embedding
-- DSL terms are AST
data Expr a where
Lit :: a → Expr a
Add :: Expr a → Expr a → Expr a
Mul :: Expr a → Expr a → Expr a
-- Interpreter
eval :: Num a => Expr a → a
eval (Lit x) = x
eval (Add e1 e2) = eval e1 + eval e2
eval (Mul e1 e2) = eval e1 * eval e23. Finally Tagless
-- Type-class based embedding
class Expr repr where
lit :: a → repr a
add :: repr a → repr a → repr a
mul :: repr a → repr a → repr a
-- Instance for interpretation
instance Expr Identity where
lit = Identity
add (Identity x) (Identity y) = Identity (x + y)
mul (Identity x) (Identity y) = Identity (x * y)
-- Instance for pretty-printing
instance Expr (Const String) where
lit x = Const (show x)
add (Const x) (Const y) = Const (x ++ " + " ++ y)
...DSL Design Patterns
Monadic DSLs
-- DSL as free monad
data DSL a where
Lift :: IO a → DSL a
PutStr :: String → DSL ()
GetLine :: DSL String
...
-- Interpret different ways
runIO :: DSL a → IO a
runIO (Lift io) = io
runIO (PutStr s) = putStr s
runIO GetLine = getLine
runSilent :: DSL a → IO a
runSilent (Lift io) = io
runSilent (PutStr _) = return ()
runSilent GetLine = return ""Arrow DSLs
-- Arrow-based DSL for computation
class Arrow arr ⇒ Process arr where
source :: arr () a
mapP :: (a → b) → arr a b
filterP :: (a → Bool) → arr a a
zipP :: arr a b → arr a c → arr a (b,c)Monad Transformers for DSLs
-- Stack DSL effects
type AppM = ReaderT Config (StateT GameState IO)
runApp :: Config → GameState → AppM a → IO (a, GameState)
runApp config state m = runStateT (runReaderT m config) stateHost Language Features for DSLs
| Feature | DSL Use |
| Type classes/traits | Overloading, type-specific ops |
| Monads | Sequencing, effects |
| Arrows | Dataflow, composition |
| Macros/code gen | Syntactic extension |
| Staging | Runtime code generation |
Applications
| Domain | DSL Examples |
| Database | LINQ, SQLAlchemy |
| Web | Yesod routes, Flask decorators |
| Build | Bazel Starlark, Make |
| Testing | QuickCheck, HSpec |
| Graphics | Shaders, OpenGL DSLs |
Quality Criteria
Your DSL embeddings must:
- Composability: Programs build from small pieces
- Abstraction: Hide implementation details
- Extensibility: Add new constructs easily
- Interpretability: Multiple backends
- Type safety: Prevent invalid programs
Implementation Checklist
- Choose embedding style: Shallow, deep, or tagless
- Define DSL signature: Operations the DSL provides
- Implement combinators: Building blocks for programs
- Build interpreter(s): Run DSL programs
- Add optimization passes: Transform DSL programs
- Handle errors: Meaningful error messages
Shallow vs Deep Tradeoffs
| Aspect | Shallow | Deep |
| Extensibility | Limited | Excellent |
| Optimization | Hard | Easy |
| Multiple backends | Hard | Easy |
| Type safety | Host determines | Must enforce |
| Performance | Direct | Indirect (interpret) |
Output Format
For DSL embedding tasks, provide:
- Embedding strategy: Why this approach
- DSL signature: Operations provided
- Combinator design: Building blocks
- Interpretation: How programs run
- Examples: Sample DSL programs
Canonical References
| Reference | Why It Matters |
| Hudak, "Building Domain-Specific Languages" | Definitive DSL book |
| Ramsey, "Enalyzing Embedded Languages" | Embedding techniques |
| Erdweg et al., "State of the Art in Language Workbenches" | Survey of DSL tools |
| Kiselyov, "Tagless Staged Interpreters" | Typed embedded DSLs |
| Bjarnason et al., "Translating Languages to Languages" | Embedding theory |
Tradeoffs and Limitations
Embedding Approach Tradeoffs
| Approach | Pros | Cons |
| Shallow | Simple, flexible | Limited optimization |
| Deep | Transformable | Complex |
| Tagless final | Type-safe, extensible | Host limits |
When NOT to Use DSL Embedding
- For general-purpose code: Use host language directly
- For performance-critical: May add overhead
- For simple tasks: External DSL may be simpler
Complexity Considerations
- Parser: External DSL needs parser
- Type checking: Must implement
- Optimization: Deep allows, shallow doesn't
Limitations
- Host language limits: Syntax, types constrain DSL
- Error messages: Hard to make clear
- Debugging: Hard to debug DSL code
- Performance: Interpretation overhead
- Tooling: IDE support limited
- Distribution: Must ship host language
Research Tools & Artifacts
Real-world DSL embeddings:
| Tool | Why It Matters |
| Haskell EDSLs | Sqlite, Parsec,加速 |
| Scala DSLs | Scala DSLs in practice |
| Rust proc-macros | Rust DSL embedding |
| Lua DSLs | Game scripting DSLs |
Famous Embeddings
- LINQ: Language-integrated query in C#
- Regex: Built-in regex in many languages
Research Frontiers
Current DSL embedding research:
| Direction | Key Papers | Challenge |
| Multi-stage | "Lightweight Monadic Reflection" | Staging DSLs |
| Polymorphic embeddings | "Embedding with Row Polymorphism" | Extensible DSLs |
| Effect DSLs | "Effect Handlers" | Effects in embedded DSLs |
Hot Topics
- Web DSLs: DSLs for web development
- Hardware DSLs: Chisel, Lava for hardware
Implementation Pitfalls
Common DSL embedding bugs:
| Pitfall | Real Example | Prevention |
| Variable capture | hygiene bugs | Use hygiene |
| Type errors | Confusing DSL errors | Clear error messages |
| Performance | Interpretation overhead | Staging / JIT |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

