
31 Mar
2009
31 Mar
'09
2:58 p.m.
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 |])