Summary
In this chapter, we studied DSLs embedded as libraries in Haskell. We saw two examples of such embedded DSLs – one for pretty-printing source code and one for financial contracts. Both revolve around an abstract data type, several combinators to construct values of that abstract data type, and one or more interpretation functions. We also studied two implementation techniques, deep and shallow embedding, as well as a refinement of the latter (“finally tagless”) for additional flexibility.
Chapter 14, Parser Combinators, complements this chapter. It introduces another example of a DSL for parsing that has been copied from Haskell to other programming languages. Moreover, this DSL is quite useful for processing standalone DSLs with a custom syntax.