Question

Well, the question is self-explicative. Suppose I want to implement some special syntax just for fun. Is it possible? What tools should I use?

Was it helpful?

Solution

There is no such meta-syntax in the Haskell standard, but there is in GHC. You can make almost any notation you want using the GHC "quasi-quotation" facilities (which are different from GHC's "Template Haskell" facility).

The GHC user guide on this is quite short, and mainly points to haskell wiki page on Quasiquotation and the implementor's home page, both of these point to the original publication: "Why It’s Nice to be Quoted: Quasiquoting for Haskell".

People have used quasi-quotation for embedding XML syntax, regular expressions, special string and text forms, and in "JMacro is a library for the programmatic generation of Javascript code."

OTHER TIPS

I guess, the best way would be to write a custom preprocessor. Several syntactic extensions started out from this approach. For instance, see:

  • DrIFt: Automatized generation of type class instances
  • arrowp: Preprocessor for arrow notation
  • c2hs: Automated generation of marshalling informations and type-signatures for FFI-bindings

and many more. The other way is to patch GHC, but this approach is rather difficult.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top