Mike, here's a piece of code that may be helpful to you: https://github.com/osa1/sc-plugin/blob/master/src/Supercompilation/Show.hs
Copy this module to your plugin, it doesn't have any dependencies other than ghc itself. When your plugin is initialized, update `dynFlags_ref` with your DynFlags as first thing to do. Then use Show instance to print AST directly. Horrible hack, but very useful for learning purposes. In fact, I don't know how else we can learn what Core is generated for a given code, and reverse-engineer to figure out details. Hope it helps. 2015-08-24 21:59 GMT-04:00 Ömer Sinan Ağacan <[email protected]>: >> Lets say I'm running the plugin on a function with signature `Floating a => a >> -> a`, then the plugin has access to the `Floating` dictionary for the type. >> But if I want to add two numbers together, I need the `Num` dictionary. I >> know I should have access to `Num` since it's a superclass of `Floating`. >> How can I get access to these superclass dictionaries? > > I don't have a working code for this but this should get you started: > > let ord_dictionary :: Id = ... > ord_class :: Class = ... > in > mkApps (Var (head (classSCSels ord_class))) [Var ord_dictionary] > > I don't know how to get Class for Ord. I do `head` here because in the case of > Ord we only have one superclass so `classSCSels` should have one Id. Then I > apply ord_dictionary to this selector and it should return dictionary for Eq. > > I assumed you already have ord_dictionary, it should be passed to your > function > already if you had `(Ord a) => ` in your function. > > > Now I realized you asked for getting Num from Floating. I think you should > follow a similar path except you need two applications, first to get > Fractional > from Floating and second to get Num from Fractional: > > mkApps (Var (head (classSCSels fractional_class))) > [mkApps (Var (head (classSCSels floating_class))) > [Var floating_dictionary]] > > Return value should be a Num dictionary. _______________________________________________ ghc-devs mailing list [email protected] http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
