question about GHC API on GHC plugin
Ömer Sinan Ağacan
omeragacan at gmail.com
Tue Aug 25 01:59:40 UTC 2015
> 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.
More information about the ghc-devs
mailing list