[Haskell-cafe] Dynamically typing TH.Exp at runtime

Martin Hofmann martin.hofmann at uni-bamberg.de
Fri Mar 13 04:03:22 EDT 2009


Sorry, maybe it I didn't made it clear enough.

> Perhaps I'm misunderstanding something, but since one can infer types
> in GHCI, that implies one can infer types in the GHC API; since Hint
> wraps the GHC API, that implies one can infer types in Hint, doesn't
> it? And indeed, there are functions to infer the type of a String;
> iirc I've even used them myself in mueval.
> 
That's true, inferring the type of a string is not the problem. However,
I am not only interested in the top-level type, but also in the type of
any arbitrary subexpression. Consider for example following recursive
definition:

foo [] = []
foo (x:xs) = (:)(x+1)(foo xs)

Typing only the first rule one would says its type is '[a] -> [a]'.
However, the second rule specialises the type to 'Num a => [a] -> [a]'.
So, if I am interested in the type of the 'x' in the pattern of the
second rule, I need to be aware of its binding on the right-hand side.
Consequently the type of 'x' is 'Num a'.

AFAIK, I need Hendley-Milner type inference for that (please correct me
if I am wrong) and I was wondering if I really need to implement it by
myself, when it is already somewhere inside GHC.

Thanks,

Martin

   



More information about the Haskell-Cafe mailing list