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
Hello Oleg, Monday, April 24, 2006, 1:52:31 AM, you wrote:
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) )
what a type "a" should have here? :) try the (10::Int) to make compiler happy -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
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@haskell.org [mailto:template-haskell-bounces@haskell.org] On Behalf Of Oleg Mürk Sent: 23 April 2006 22:53 To: template-haskell@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
participants (3)
-
Bulat Ziganshin -
Oleg Mürk -
Simon Peyton-Jones