# Embedded domain specific language

### From HaskellWiki

(Difference between revisions)

(→Discussion of common problems: Added a link to "Haskell eDSL Tutorial - Shared expenses") |
(Added section "Blog articles") |
||

Line 1: | Line 1: | ||

'''Embedded Domain Specific Language''' means that you embed a [http://en.wikipedia.org/wiki/Domain_specific_language Domain specific language] in a language like Haskell. |
'''Embedded Domain Specific Language''' means that you embed a [http://en.wikipedia.org/wiki/Domain_specific_language Domain specific language] in a language like Haskell. |
||

E.g. using the [http://cryp.to/funcmp/ Functional MetaPost library] you can write Haskell expressions, which are then translated to MetaPost, MetaPost is run on the generated code and the result of MetaPost can be post-processed in Haskell. |
E.g. using the [http://cryp.to/funcmp/ Functional MetaPost library] you can write Haskell expressions, which are then translated to MetaPost, MetaPost is run on the generated code and the result of MetaPost can be post-processed in Haskell. |
||

+ | |||

== Degree of embedding == |
== Degree of embedding == |
||

Line 8: | Line 9: | ||

* Shallow embedding: All Haskell operations immediately translate to the target language. E.g. the Haskell expression <hask>a+b</hask> is translated to a <hask>String</hask> like <hask>"a + b"</hask> containing that target language expression. |
* Shallow embedding: All Haskell operations immediately translate to the target language. E.g. the Haskell expression <hask>a+b</hask> is translated to a <hask>String</hask> like <hask>"a + b"</hask> containing that target language expression. |
||

* Deep embedding: Haskell operations only build an interim Haskell data structure that reflects the expression tree. E.g. the Haskell expression <hask>a+b</hask> is translated to the Haskell data structure <hask>Add (Var "a") (Var "b")</hask>. This structure allows transformations like optimizations before translating to the target language. |
* Deep embedding: Haskell operations only build an interim Haskell data structure that reflects the expression tree. E.g. the Haskell expression <hask>a+b</hask> is translated to the Haskell data structure <hask>Add (Var "a") (Var "b")</hask>. This structure allows transformations like optimizations before translating to the target language. |
||

+ | |||

== Discussion of common problems == |
== Discussion of common problems == |
||

Line 20: | Line 22: | ||

* Tom Lokhorst [http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video AwesomePrelude presentation (video)] |
* Tom Lokhorst [http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video AwesomePrelude presentation (video)] |
||

* Leandro Lisboa Penz [http://lpenz.github.com/articles/hedsl-sharedexpenses/ Haskell eDSL Tutorial - Shared expenses] |
* Leandro Lisboa Penz [http://lpenz.github.com/articles/hedsl-sharedexpenses/ Haskell eDSL Tutorial - Shared expenses] |
||

+ | |||

+ | |||

+ | == Blog articles == |
||

+ | |||

+ | * [http://donsbot.wordpress.com/2007/03/10/practical-haskell-shell-scripting-with-error-handling-and-privilege-separation/ Practical Haskell: shell scripting with error handling and privilege separation] |
||

+ | |||

[[Category:Glossary]] |
[[Category:Glossary]] |

## Revision as of 20:48, 7 February 2012

**Embedded Domain Specific Language** means that you embed a Domain specific language in a language like Haskell.
E.g. using the Functional MetaPost library you can write Haskell expressions, which are then translated to MetaPost, MetaPost is run on the generated code and the result of MetaPost can be post-processed in Haskell.

## 1 Degree of embedding

There are two major degrees of embedding:

- Shallow embedding: All Haskell operations immediately translate to the target language. E.g. the Haskell expression is translated to aa+blikeStringcontaining that target language expression."a + b"
- Deep embedding: Haskell operations only build an interim Haskell data structure that reflects the expression tree. E.g. the Haskell expression is translated to the Haskell data structurea+b. This structure allows transformations like optimizations before translating to the target language.Add (Var "a") (Var "b")

## 2 Discussion of common problems

Sharing and recursion are common problems when implementing DSLs. Often some kind of observable sharing is requested that requires a deep embedding.

- Oleg in Haskell-Cafe about Designing DSL with explicit sharing (was: I love purity, but it's killing me)
- Koen Classen: Observable Sharing for Functional Circuit Description
- Andy Gill: Type-Safe Observable Sharing
- Tom Lokhorst AwesomePrelude presentation (video)
- Leandro Lisboa Penz Haskell eDSL Tutorial - Shared expenses