Template Haskell

Template Haskell is an experimental language extension to the Haskell programming language 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 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+ |]

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:

result = $( transform [| input |] )
gollark: They would work as more reliable long-term investments.
gollark: That and firms.
gollark: And my idea for how the buying/selling would work is that you'd create a "sell order" if you wanted to sell it, and set a price, and your share would be sold as soon as anyone created a "buy order" with that price or a higher one.
gollark: The auctioning could be done with a Vickrey auction, which apparently "gives bidders an incentive to bid their true value", which seems like a good property.
gollark: My suggested way for it to work has always been having meme shares pay dividends (based on upvotes, maybe every hour or after a fixed time or something), giving the creator some of the shares, and selling the others to "the market" (maybe via some sort of short auction mechanism?), then just letting everyone trade them freely until they pay out.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.