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.
Diagrams is a Haskell embedded DSL for creating vector graphics. Here is some diagrams DSL 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 is a small command-line utility that converts diagrams drawn using ascii art into bitmap graphics.
+--------+ +-------+ +-------+ | | --+ ditaa +--> | | | Text | +-------+ |diagram| |Document| |!magic!| | | | {d}| | | | | +---+----+ +-------+ +-------+ : ^ | Lots of work | +-------------------------+
Needle is a domain specific language for ASCII-fied arrow notation.
{-# LANGUAGE QuasiQuotes #-} fNeedle :: (Int, Int, Int) -> (Int, Int, Int, Int) fNeedle = [nd| }=={(+1)}=\==========================> \ }===\ \ /============> \ \ / }=) \ (==={uncurry div}=/={negate}===> \ \=={(*2)}========================> |]
*Main> fNeedle (1,2,3) (2,0,0,4)
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.
The LabVIEW generates a bitfile from an algorithm design expressed in G, which can be used to configure an FPGA.