Embedded domain specific language: Difference between revisions

From HaskellWiki
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
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.
<span>{{DISPLAYTITLE:embedded domain specific language}}</span>
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.
 
'''Embedded Domain Specific Language''': a [http://en.wikipedia.org/wiki/Domain_specific_language domain specific language] which is defined within a language like Haskell.
E.g. using the [https://hackage.haskell.org/package/funcmp Functional MetaPost library] you can write Haskell expressions, which are then translated to [https://en.wikipedia.org/wiki/MetaPost MetaPost] (which produces vector graphic diagrams from geometric/algebraic descriptions), MetaPost is run on the generated code and the result of MetaPost can be post-processed in Haskell.




Line 40: Line 42:
* [http://www.yesodweb.com/book/templates#file253-synopsis Hamlet, Julius, Cassius and Lucius] are languages embedded in the [http://www.yesodweb.com/ Yesod framework]
* [http://www.yesodweb.com/book/templates#file253-synopsis Hamlet, Julius, Cassius and Lucius] are languages embedded in the [http://www.yesodweb.com/ Yesod framework]


* [https://serokell.io/blog/lorentz-implementing-smart-contract-edsl-in-haskell Lorentz: Implementing Smart Contract eDSL in Haskell]  Lorenz is a Haskell eDSL for Michelson smart contracts language [https://gitlab.com/camlcase-dev/michelson-tutorial/blob/master/README.md]
== More to read/view ==
== More to read/view ==



Latest revision as of 11:09, 17 February 2025

Embedded Domain Specific Language: a domain specific language which is defined within a language like Haskell. E.g. using the Functional MetaPost library you can write Haskell expressions, which are then translated to MetaPost (which produces vector graphic diagrams from geometric/algebraic descriptions), MetaPost is run on the generated code and the result of MetaPost can be post-processed in Haskell.


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.


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.

Examples of Domain Specific Languages

  • Functional MetaPost (funcmp) is a Haskell frontend to the MetaPost language by John Hobby. Users write their graphics as Haskell programs, which then emit MetaPost code that can be compiled into encapsulated PostScript files and smoothly included into e.g. LaTeX.
  • orc: Orchestration-style coordination EDSL
  • The diagrams-cairo package. A full-featured backend for rendering diagrams using the cairo rendering engine. To get started, see Diagrams.Backend.Cairo.CmdLine.
  • Workflow: library for transparent execution of interruptible computations

More to read/view