Getting the inferred types of TH's UnboundVarEs

Sandy Maguire sandy at sandymaguire.me
Wed Mar 18 01:55:50 UTC 2020


Hi all,

I'm writing some TH code that should generate property tests. For example,
the expression:

$(generate [e| law "idempotent" (insert a (insert a b) == insert a b) |])

should generate the code

property $ \a b -> insert a (insert a b) === insert a b

I do this by looking for UnboundVarEs in the Exp returned by the [e| quote,
and binding them in a lambda. All of this works.

However, now I'm trying to get the inferred types of `a` and `b` in the
above. GHC clearly is typechecking the quote, since it will fail if I
replace `b` with something nonsensical. *Is there some existent way to get
the inferred type of an UnboundVarE --- ideally without reimplementing the
typechecker?*

Thanks!
Sandy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20200317/9b889967/attachment.html>


More information about the ghc-devs mailing list