## Four Interesting DSLs

Posted on December 4, 2014

Here are a few interesting DSLs. Traditional programming languages are usually textual documents with lots of `;` a few `foo(..)` and maybe a `data Bar = ...`. But this is not always the case! Below are four DSLs.

1. A traditional textual language to generate graphics.
2. An ascii visual language to generate graphics.
3. A graphical language to generate hardware.

#### Diagrams

Diagrams is a Haskell embedded DSL for creating vector graphics. Here is some diagrams DSL code:

##### Diagrams code
```circleSqT   = square 1 `atop` circle 1 # translate (r2 (0.5, 0.3))
circleSqHT  = square 1 ||| circle 1 # translate (r2 (0.5, 0.3))
circleSqHT2 = square 1 ||| circle 1 # translate (r2 (19.5, 0.3))
example = hcat [circleSqT, strutX 1, circleSqHT, strutX 1, circleSqHT2]
```

#### Ditaa

Ditaa is a small command-line utility that converts diagrams drawn using ascii art into bitmap graphics.

##### Ditaa code
```    +--------+   +-------+    +-------+
|        | --+ ditaa +--> |       |
|  Text  |   +-------+    |diagram|
|Document|   |!magic!|    |       |
|     {d}|   |       |    |       |
+---+----+   +-------+    +-------+
:                         ^
|       Lots of work      |
+-------------------------+
```

#### Needle

Needle is a domain specific language for ASCII-fied arrow notation.

##### Needle code
```{-# LANGUAGE QuasiQuotes #-}

fNeedle :: (Int, Int, Int) -> (Int, Int, Int, Int)
fNeedle = [nd|
}=={(+1)}=\==========================>
\
}===\     \             /============>
\     \             /
}=) \ (==={uncurry div}=/={negate}===>
\
\=={(*2)}========================>
|]
```
##### Needle output
```*Main> fNeedle (1,2,3)
(2,0,0,4)
```

#### “G” in LabVIEW

This is my favourite DSL of the four, because what is shown below is a while loop structure in the G language. National Instruments might not describe “G” as a DSL, but it certainly is one. LabVIEW is a system-design platform and development environment for “G”, a visual programming language from National Instruments.

##### G output

The LabVIEW generates a bitfile from an algorithm design expressed in G, which can be used to configure an FPGA.