Difference between revisions of "Embedded domain specific language"

From HaskellWiki
Jump to navigation Jump to search
(observable sharing in graphs)
(fixed broken link, added Metapost description)
 
(11 intermediate revisions by 6 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.
 
'''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 [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 18: Line 18:
   
 
* Oleg in Haskell-Cafe about [http://www.haskell.org/pipermail/haskell-cafe/2008-February/039639.html Designing DSL with explicit sharing (was: I love purity, but it's killing me)]
 
* Oleg in Haskell-Cafe about [http://www.haskell.org/pipermail/haskell-cafe/2008-February/039639.html Designing DSL with explicit sharing (was: I love purity, but it's killing me)]
* Koen Classen: [http://www.cs.chalmers.se/~koen/pubs/entry-asian99-lava.html Observable Sharing for Functional Circuit Description]
+
* Koen Classen: [http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.4053 Observable Sharing for Functional Circuit Description]
* Andy Gill: [http://www.ittc.ku.edu/~andygill/paper.php?label=DSLExtract09 Type-Safe Observable Sharing]
+
* Andy Gill: [http://www.ittc.ku.edu/~andygill/papers/reifyGraph.pdf 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]
+
* Leandro Lisboa Penz [http://www.lpenz.org/articles/hedsl-sharedexpenses/ Haskell eDSL Tutorial - Shared expenses]
 
* Bruno Oliveira and William Cook: [http://www.cs.utexas.edu/~wcook/Drafts/2012/graphs.pdf Functional Programming with Structured Graphs]
 
* Bruno Oliveira and William Cook: [http://www.cs.utexas.edu/~wcook/Drafts/2012/graphs.pdf Functional Programming with Structured Graphs]
  +
* Emil Axelsson and Koen Claessen: [http://www.cse.chalmers.se/~emax/documents/axelsson2013using.pdf Using Circular Programs for Higher-Order Syntax]
  +
* Oleg Kiselyov: [http://okmij.org/ftp/tagless-final/sharing/sharing.pdf Implementing explicit and finding implicit sharing in embedded DSLs]
   
 
== Examples of Domain Specific Languages ==
 
== Examples of Domain Specific Languages ==
   
* [http://hackage.haskell.org/package/funcmp Functional MetaPost] 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.
+
* Functional MetaPost ({{HackagePackage|id=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.
   
* [http://hackage.haskell.org/package/orc orc]: Orchestration-style coordination EDSL
+
* {{HackagePackage|id=orc}}: Orchestration-style coordination EDSL
   
  +
* {{HackagePackage|id=synthesizer-llvm}} provides [[Synthesizer|audio signal processing functions]] that are translated to [[LLVM]] assembly language. This warrants very fast computation. It uses shallow embedding.
* [http://hackage.haskell.org/package/diagrams-cairo The diagrams-cairo package]. A full-featured backend for rendering diagrams using the cairo rendering engine. To get started, see Diagrams.Backend.Cairo.CmdLine.
 
   
 
* The {{HackagePackage|id=diagrams-cairo}} package. A full-featured backend for rendering diagrams using the cairo rendering engine. To get started, see Diagrams.Backend.Cairo.CmdLine.
* [http://hackage.haskell.org/package/Workflow Workflow]: library for transparent execution of interruptible computations
 
  +
 
* {{HackagePackage|id=Workflow}}: library for transparent execution of interruptible computations
   
 
* [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 ==
   
  +
* [http://cacm.acm.org/magazines/2011/7/109910-dsl-for-the-uninitiated/fulltext DSL for the Uninitiated], an introduction to DSLs, not Haskell-specific
 
* [http://skillsmatter.com/podcast/scala/haskell-for-embedded-domain-specific-languages Haskell for embedded domain-specific languages] (podcast)
 
* [http://skillsmatter.com/podcast/scala/haskell-for-embedded-domain-specific-languages Haskell for embedded domain-specific languages] (podcast)
 
* [[Research papers/Domain specific languages]]
 
* [[Research papers/Domain specific languages]]
 
* [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] (blog article)
 
* [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] (blog article)
  +
* [http://www.reddit.com/r/haskell/comments/2e8d53/whats_the_best_practice_for_building_a_dsl_in/ What's the best practice for building a DSL in haskell?], a discussion at Reddit
 
  +
* [https://serokell.io/blog/tagless-final Introduction to Tagless Final]
 
   
 
[[Category:Glossary]]
 
[[Category:Glossary]]

Latest revision as of 10:22, 10 June 2021

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 (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