Implementing DSLs
There are two main techniques for implementing an embedded DSL in Haskell: deep embedding and shallow embedding. Each has its advantages and disadvantages, and we will study both.
Running example
To illustrate the deep embedding technique, and later the shallow embedding, we will use a small DSL for describing geometric regions. This DSL was originally developed for a prototype system in a US Navy study. The prototype had to keep track of where different entities (ships, planes, and so on) were concerning each other. Different regions (also called zones) have different significance: coming too close to friendly units is interpreted as hostile intent, certain corridors are reserved for airline routes, and so on.
The core abstract data type in this DSL is Region
. There are several combinators for constructing such regions. For the sake of minimality, we’ll only consider three here:
- A primitive region is a circular shape around the origin, with...