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?
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."
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.
© 2022 - 2024 — McMap. All rights reserved.