encyclopegia.org

Template Haskell

Template Haskell (Template Meta-Haskell for early versions) is an experimental language extension to the functional programming language Haskell, implemented in the Glasgow Haskell Compiler (GHC) version 6 and later. It allows compile time metaprogramming and generative programming by means of manipulating abstract syntax trees and 'splicing' results back into a program. The abstract syntax is represented using ordinary Haskell data types 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. As of GHC-6.10, Template Haskell provides support for user-defined quasi-quoters, which allows users to write parsers which can generate Haskell code from an arbitrary syntax. This syntax is also enforced at compile time. For example, using a custom quasi-quoter for regular expressions could look like this: digitsFollowedByLetters = [$re| \d+ \s+ |]

Template Haskell (Template Meta-Haskell for early versions) is an experimental language extension to the functional programming language Haskell, implemented in the Glasgow Haskell Compiler (GHC) version 6 and later. It allows compile time metaprogramming and generative programming by means of manipulating abstract syntax trees and 'splicing' results back into a program. The abstract syntax is represented using ordinary Haskell data types 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. As of GHC-6.10, Template Haskell provides support for user-defined quasi-quoters, which allows users to write parsers which can generate Haskell code from an arbitrary syntax. This syntax is also enforced at compile time. For example, using a custom quasi-quoter for regular expressions could look like this: digitsFollowedByLetters = [$re| \d+ \s+ |] result = $( transform [| input |] )

References

No reference rows published for this article.

Cite this article

MLA

"Template Haskell." encyclopegia.org, 2024, https://encyclopegia.org/wiki/template-haskell. Accessed 25 November 2026.

Chicago

"Template Haskell." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/template-haskell.

APA

encyclopegia.org. (2024). Template Haskell. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/template-haskell

Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Template:New Wave (Contest)

stub · references available

Template:Support

stub · references available

Template:Lang-tr

stub · references available

Template:Footy-stub

stub · references available

Template:Location map Iceland

stub · references available

Template:Location map Sweden, 40south

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1256509154 · 0.5 · snapshot enwiki-001256509154

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.