[Haskell-cafe] ghc-devs at haskell.org

Robin Palotai palotai.robin at gmail.com
Tue Sep 19 05:36:01 UTC 2017


Hello GHC devs,

Before inventing the wheel, want to check if there is a GHC API way to look
up the (fully) resolved instance method from a class method.

For example, given a code

    data Foo Int deriving Show

    bar = show (Foo 3)

when inspecting the Typechecked AST for bar's show call, I would like to
get to the Name / Id of 'show' of the 'Show' typeclass.

I believe I could use splitHsSigmaTy on the HsType of the function call to
get the context, and then evaluate the HsWrapper somehow to find out what
instance dictionary is applied to the class restriction in the context, and
then look up the instance method from the dictionary..

Two questions:

1) Is there maybe functionality for this?

2) If not, is there any guarantee about the constraint order in the
context, at the method call? So I could more easily determine which
constraint's application to look for..

Any hints welcome && Thank you!
Robin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170919/2b774629/attachment.html>


More information about the Haskell-Cafe mailing list