Shallow vs Deep Embedding

  • A domain-specific language (DSL) can be implemented by embedding it within a general-purpose host language
  • This embedding may be shallow or deep

Shallow

  • Terms in the DSL are implemented directly as the values to which they evaluate, bypassing the intermediate AST
  • “DSL syntax is modelled with the host language’s existing syntax”

Deep

  • Terms in the DSL are implemented to construct an AST
  • AST is then transformed for optimization and traversed for evaluation
  • “DSL syntax is modelled in a way to which we can actually manipulate it”

References