Re: Determine instance method from class method callsite

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Determine instance method from class method callsite

Robin Palotai
My conclusion so far: there's no royal way. One can get the instance dictionary DFunId pretty easy, but then access to the Typechecked AST of the instance declaration is really needed to find all the method bindings $c... (that get applied when constructing the dictionary $d...).

2017-09-19 7:38 GMT+02:00 Robin Palotai <[hidden email]>:
Sorry, I messed up subject and mailing list. Copying to both list now after the mistake (wanted only ghc-devs for specificity).

Thanks!

2017-09-19 7:36 GMT+02:00 Robin Palotai <[hidden email]>:
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



_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.