RE: Question regarding template Haskell
[I'm redirecting this to the Template Haskell mailing list, where it more properly belongs.] Interesting question. Tim and I are working on revising the 'reifyType' story, but even in our revised version, your program will be rejected with a staging error. reifyType gives a way to consult the compiler's type environment, at the moment when the ExpQ is run. But at that moment 'x' isn't in scope any more. [Tim: this might make a good example for the design notes you're working on.] You might instead wonder if you can write getup :: ExpQ -> ExpQ which asks what the type of the expression passed to it is. This one has come up before, and I don't think we have a good answer yet. Trouble is (a) although quoted code is type-checked, there's not enough info to do a full type-check (b) it's not obvious how to record whatever the type checker does discover. Still an open question, then. Simon | -----Original Message----- | From: libraries-bounces@haskell.org [mailto:libraries-bounces@haskell.org] On Behalf Of Yu Di | Sent: 12 September 2003 03:33 | To: libraries@haskell.org | Subject: Question regarding template Haskell | | Hi, I have a question regarding template Haskell: from | the documentation, I have the impression that it is | impossible to reify the type of the variable passed to | the template function, is this true? Or, in other | words, can I write a function like: | | getTupleCount :: a -> ExpQ | | getTupleCount x= | do | t <- (reifyType x) | --work on t | ... | | which returns an expression that is an integer for any | tuple input, but reduces to error for any input that | is not a tuple? | | Thanks! | | Di, Yu | 9.11 | | __________________________________ | Do you Yahoo!? | Yahoo! SiteBuilder - Free, easy-to-use web site design software | http://sitebuilder.yahoo.com | _______________________________________________ | Libraries mailing list | Libraries@haskell.org | http://www.haskell.org/mailman/listinfo/libraries
On 17/09/2003, at 7:45 PM, Simon Peyton-Jones wrote:
| Hi, I have a question regarding template Haskell: from | the documentation, I have the impression that it is | impossible to reify the type of the variable passed to | the template function, is this true? Or, in other | words, can I write a function like: | | getTupleCount :: a -> ExpQ | | getTupleCount x= | do | t <- (reifyType x) | --work on t | ...
If your 'x' variable is monomorphic, you can use the rType function that Sean and I came up with, detailed here: http://www.haskell.org/pipermail/template-haskell/2003-July/000128.html That currently handles only 2-tuples, but it shouldn't be too hard to extend it to work on any-size tuples. Let me know if you're having problems. -- % Andre Pang : trust.in.love.to.save
participants (2)
-
ozone@algorithm.com.au -
Simon Peyton-Jones