Getting the inferred types of TH's UnboundVarEs

Matthew Pickering matthewtpickering at gmail.com
Wed Mar 18 08:04:18 UTC 2020


Good morning Sandy, thanks for your email.

I don't think that GHC will typecheck the quote until you splice it
in. What exactly do you mean that it fails if `b` is replaced with
something different?

What are you hoping to do with this information?

This reminds me a bit of the `qTypecheck` action I have implemented on
another branch -
https://gitlab.haskell.org/ghc/ghc/issues/17565#note_242199

Cheers,

Matt

On Wed, Mar 18, 2020 at 1:56 AM Sandy Maguire <sandy at sandymaguire.me> wrote:
>
> 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
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


More information about the ghc-devs mailing list