[Template-haskell] Type inference

Simon Peyton-Jones simonpj at microsoft.com
Tue Apr 25 03:52:35 EDT 2006


It's expected but unfortunate.  Template Haskell runs *during* type checking.  So when you reify a local type, it may not yet be fully worked out.  In this case it would be worse if you said

 

          let a=10 

          in ( $(...reify 'a...),  a+1::Int )

 

Here it's "clear" that a has type Int, but it won't be clear to Template Haskell until after it's typechecked the whole expression.  But it has to run the splice before that! 

 

That's a shortcoming I don't know how to solve at the moment.

 

Simon

 

________________________________

From: template-haskell-bounces at haskell.org [mailto:template-haskell-bounces at haskell.org] On Behalf Of Oleg Mürk
Sent: 23 April 2006 22:53
To: template-haskell at haskell.org
Subject: [Template-haskell] Type inference

 

Hello,

I have the following problem. I'd like to infer types of local bindings using 'reify':
------------------------------------
testValue = 
    let
        a = 10
    in
        $(do
            VarI _ t _ _ <- reify 'a
            lift (pprint t)
        )
-------------------------------------
But this code prints only:
-------------------------------------
*Debug> testValue
"t_0"
-------------------------------------
Is this intended behavior? Are there any workarounds? 
Things work fine if symbol is defined in another module.
I do realise that in general $(...) may add additional constraints on local variables.

OM

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/template-haskell/attachments/20060425/608b5642/attachment.htm


More information about the template-haskell mailing list