- Template Haskell
Template Haskell is an experimental language extension to the programming language Haskell implemented in the Glasgow Haskell
Compiler (version 6 and later).In early incarnations it was also known as Template Meta-Haskell.
It allows compile-time
metaprogramming andgenerative programming by means of manipulatingabstract syntax tree s and 'splicing ' results back into a program. The abstract syntax is represented using ordinary Haskelldata type s and the manipulations are performed using ordinary Haskell functions.'
Quasi-quote ' brackets[|
and|]
are used to get the abstract syntax tree for the enclosed expression and 'splice' brackets$(
and)
are used to convert from abstract syntax tree into code.Example
A common idiom is to quasi-quote an expression, perform some transformation on the expression and splice the result back into the program. It could be written as:
foo = $( transform [| bar |] )
External links
* [http://www.haskell.org/haskellwiki/Template_Haskell Template Haskell Wiki Page]
* [http://www.haskell.org/th/ The Template Haskell Home Page (rather old at this moment)]
Wikimedia Foundation. 2010.