[Template-haskell] types.
Keean Schupke
k.schupke at imperial.ac.uk
Fri Feb 18 10:33:45 EST 2005
Last mail seemed to get lost (think I forgot to CC it to the list):
would this work with:
$(something [d| f a = a + 1 |])
Such that I can reference the reified type of 'f' from inside 'something'.
'something' would be imported from another file. I am using ghc-6.4
Keean.
Sean Seefried wrote:
>
> On 18/02/2005, at 8:11 PM, Keean Schupke wrote:
>
>> Is it possible to get at type information from TH? I am thinking of
>> something
>> like the following:
>>
>> f a = a + 1
>>
>> {- ghc derives the type: f :: Integral a => a -> a -}
>>
>> Can I get at this derives type information? It would be very useful
>> for the project I am working on... can I just reify the type of the
>> function?
>>
>
> The answer to this question is a little tricky - it's yes with a few
> caveats. Firstly, the Q monad can be "run" in two contexts - within
> the IO monad and with in the TcM monad of the GHC compiler. You can't
> you `reify' to get type information in the former context.
> Secondly, you can only reify the type of something that has been
> imported from another module. No go on the reifying something
> declared within the module you're reifying in.
>
> I have two pieces of sample code that demonstrate the Q monad being
> run within the TcM monad and within the IO monad. The first one
> works, the second doesn't. They are attached.
>
> These built in an old version of GHC 6.3. They should compile and run
> in GHC 6.5 without *too* much difficulty although I haven't tested it.
>
> Cheers,
>
> Sean
>
More information about the template-haskell
mailing list