Skip to main content

Typed Quote/Antiquote—Or: Compile−time Parsing

Ralf Hinze

Abstract

Haskell is often used as a host language for embedding other languages. Typically, the abstract syntax of the guest language is defined by a collection of data type declarations; parsers and pretty-printers convert between the concrete syntax and its abstract representation. A quote/antiquote mechanism permits a tighter integration of the guest language into the host language by allowing one to use phrases in the guest language's concrete syntax. A quote/antiquote mechanism usually requires an extension of the host language. The purpose of this pearl is to show that one can program such a mechanism within Haskell itself. The technique is based on Okasaki's flattening combinators.

Journal
JFP
Number
3
Pages
219–234
Volume
21
Year
2011