Personal tools

Embedded domain specific language

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(degrees of embedding)
(Discussion of common problems: Added a link to "Haskell eDSL Tutorial - Shared expenses")
Line 19: Line 19:
 
* Andy Gill: [http://www.ittc.ku.edu/~andygill/paper.php?label=DSLExtract09 Type-Safe Observable Sharing]
 
* Andy Gill: [http://www.ittc.ku.edu/~andygill/paper.php?label=DSLExtract09 Type-Safe Observable Sharing]
 
* 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]
   
 
[[Category:Glossary]]
 
[[Category:Glossary]]

Revision as of 10:04, 30 June 2011

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
    a+b
    is translated to a
    String
    like
    "a + b"
    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
    a+b
    is translated to the Haskell data structure
    Add (Var "a") (Var "b")
    . This structure allows transformations like optimizations before translating to the target language.

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.