Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Template Haskell

From Wikipedia, the free encyclopedia
Computer language extension
This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages)
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Template Haskell" – news ·newspapers ·books ·scholar ·JSTOR
(October 2021) (Learn how and when to remove this message)
The topic of this articlemay not meet Wikipedia'sgeneral notability guideline. Please help to demonstrate the notability of the topic by citingreliable secondary sources that areindependent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to bemerged,redirected, ordeleted.
Find sources: "Template Haskell" – news ·newspapers ·books ·scholar ·JSTOR
(December 2019) (Learn how and when to remove this message)
(Learn how and when to remove this message)

Template Haskell (Template Meta-Haskell for early versions) is an experimental language extension to thefunctionalprogramming languageHaskell, implemented in theGlasgow Haskell Compiler (GHC) version 6 and later.[1]

It allowscompile timemetaprogramming andgenerative programming by means of manipulatingabstract syntax trees and 'splicing' results back into a program. The abstract syntax is represented using ordinary Haskelldata types and the manipulations are performed using ordinary Haskellfunctions.

'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 forregular expressions could look like this:

digitsFollowedByLetters=[$re|\d+\s+|]

Example

[edit]

A common idiom is to quasi-quote anexpression, perform some transformation on the expression and splice the result back into the program. It could be written as:

result=$(transform[|input|])

References

[edit]
  1. ^Sheard, Tim;Jones, Simon Peyton (3 October 2002)."Template meta-programming for Haskell".Proceedings of the 2002 ACM SIGPLAN workshop on Haskell. Association for Computing Machinery. pp. 1–16.doi:10.1145/581690.581691.ISBN 1581136056.S2CID 6096655.

External links

[edit]
Haskell programming
Software
Implementations
(features)
Dialects
Electronic
design
Libraries
Package managers
Windowing systems
Web frameworks
Book
Community
Eponym
Italics= discontinued° =Open-source software
BookCategories:FamilySoftware
Retrieved from "https://en.wikipedia.org/w/index.php?title=Template_Haskell&oldid=1256509154"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp