Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Template Haskell
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Computer language extension}} {{Multiple issues| {{More citations needed|date=October 2021}} {{Notability|date=December 2019}} }} '''Template Haskell''' ('''Template Meta-Haskell''' for early versions) is an experimental language extension to the [[Functional programming|functional]] [[programming language]] [[Haskell]], implemented in the [[Glasgow Haskell Compiler]] (GHC) version 6 and later.<ref name="Sheard2002">{{cite book |last1=Sheard |first1=Tim |last2=Jones |first2=Simon Peyton |author2-link=Simon Peyton Jones |date=3 October 2002 |title=Proceedings of the 2002 ACM SIGPLAN workshop on Haskell |chapter=Template meta-programming for Haskell |pages=1β16 |doi=10.1145/581690.581691 |chapter-url=https://dl.acm.org/doi/10.1145/581690.581691 |publisher=Association for Computing Machinery |isbn=1581136056 |s2cid=6096655}}</ref> It allows [[compile time]] [[metaprogramming]] and [[generative programming]] by means of manipulating [[abstract syntax tree]]s and '[[wikt:splice|splicing]]' results back into a program. The abstract syntax is represented using ordinary Haskell [[data type]]s and the manipulations are performed using ordinary Haskell [[Function (mathematics)|functions]]. '[[Quasi-quote]]' brackets <code>[|</code> and <code>|]</code> are used to get the abstract syntax tree for the enclosed expression and 'splice' brackets <code>$(</code> and <code>)</code> 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: <syntaxhighlight lang="haskell"> digitsFollowedByLetters = [$re| \d+ \s+ |] </syntaxhighlight> == Example == A common idiom is to quasi-quote an [[expression (programming)|expression]], perform some transformation on the expression and splice the result back into the program. It could be written as: <syntaxhighlight lang="haskell"> result = $( transform [| input |] ) </syntaxhighlight> == References == {{Reflist}} == External links == * [http://www.haskell.org/haskellwiki/Template_Haskell Haskell.org Template Haskell Wiki page] {{Haskell programming}} [[Category:Experimental programming languages]] [[Category:Haskell programming language family]] [[Category:Functional languages]] [[Category:Metaprogramming]] <!-- Hidden categories below --> [[Category:Articles with example Haskell code]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Haskell programming
(
edit
)
Template:Multiple issues
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)