[Haskell-cafe] Get a variable's type in quasiquote

Jonathan Geddes geddes.jonathan at gmail.com
Thu Jan 5 21:47:02 CET 2012


Oops I didn't get to finish... accidentally sent. Here's the completed
version:

I'm playing around with Template Haskell, specifically QuasiQuotes and I've
run into something that I hope is not an inherent limitation in
TH.Specifically I want to get the type of a variable whose name is used in
a QuasiQuote. The code generated by the QQ should depend on the type of the
variables that are to be antiquoted.

For example

let a = True
in [qq | a |]

should result in different code being generated by the qq than

let a = 42
in [qq | a |]


because the type of variable "a" is different.

So far I've tried simple reification

> quote str = do
>   let varname = "someVariableKnownToExist"
>   info <- reify $ mkName str
>   ...

but this results in "`someVariableKnownToExists' is not in scope at a reify"

any thoughts?

--J Arthur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120105/4d929d90/attachment.htm>


More information about the Haskell-Cafe mailing list