Accessing dictionaries from a GHC plugin
ben at smart-cactus.org
Fri Apr 22 13:01:49 UTC 2016
Yannick Boesmans <yannick.boesmans at gmail.com> writes:
> In my module with definitions, Free, Con, Var, the (+), Inl and Inr are
> defined and the foldFree function is defined.
> There is also a functor instance: instance (Functor f, Functor g) =>
> Functor (f + g)
> The problem is that when trying to do this transformation in GHC Core, I
> only get a dictionary for the functor g, but not for Nondet or for
> (Nondet + g).
> What is need is of the form:
> @ Nondet @ g_a2MS Types.$fFunctorNondet $dFunctor_a2R9)
> and I have access to @ Nondet, @ g_a2MS and $dFunctor_a2R9, but I don't
> know how to find WhatMorphism.Free.$fFunctor+ and Types.$fFunctorNondet.
Ahh, I see; is DataCon.classDataCon perhaps what you are looking for?
Given the Class you should be able to construct the needed dictionary
(hopefully it's not too difficult to construct).
Looking up your class will likely involve starting with the OccName,
looking it up in the name cache, then using MonadThings.lookupTyCon to
grab the TyCon. Then you can use TyCon.tyConClass_maybe to fetch the
Class from your TyCon. Then you should have everything you need to
construct your dictionary.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 472 bytes
Desc: not available
More information about the ghc-devs