[Haskell-cafe] [Probably a dumb question] Quasiquoting

Robert Greayer robgreayer at yahoo.com
Tue Mar 31 14:58:22 EDT 2009

Andrew Coppin wrote:
| Is there some reason why you can't have antiquoting with normal TH?
| I'm just trying to make sure I've understood QQ correctly...

With TH, it might not be necessary (depending on the situation)...

> {-# OPTIONS_GHC -XTemplateHaskell #-}
> module QT where
> import Language.Haskell.TH
> foo s = $([| "hello " ++ s |])

The TH quotation builds a TH expression (of type Q Exp) in which there is a variable 's' which is free.  Since it's spliced into a context that happens to bind an 's', it compiles...

But you can also splice into your quotes:

> bar s = $(let v = varE (mkName "s") in [| "hello " ++ $v |])


More information about the Haskell-Cafe mailing list