Hi,
We tried to do something similar a few years ago and couldn't get a nice solution for this.
We ended up just requiring the user code to define a binding with a hard-coded name as a struct containing everything. I got the impression that the plugin ran too late in the pipeline to load new modules, so we couldn't add an import for the module we wanted.

https://github.com/DDCSF/repa/blob/master/icebox/abandoned/repa-plugin/Data/Array/Repa/Plugin/Primitives.hs#L142
https://github.com/DDCSF/repa/blob/master/icebox/abandoned/repa-plugin/test/01-Simple/Main.hs#L11

On Fri, 18 Nov 2016 at 19:36 J. Stutterheim <j.stutterheim@me.com> wrote:
Hi all,

I'm looking for a way to add my own wired-in package/module/type class for use in a core-to-core plugin.

My first challenge is to identify the type class that I want to find. I have the following code:

        myPkgUnitId :: UnitId
        myPkgUnitId = fsToUnitId (fsLit "mypackage")

        mkMyModule :: FastString -> Module
        mkMyModule m = mkModule myPkgUnitId (mkModuleNameFS m)

        myModule :: Module
        myModule = mkMyModule (fsLit "My.Module")

        myClassName :: Name
        myClassName = clsQual myModule (fsLit "MyClass") myClassKey

        myClassKey  :: Unique -- How do I get this?

Here the missing piece is the myClassKey. Looking at how this is done for, e.g., the Monad class:

        monadClassKey  :: Unique
        monadClassKey = mkPreludeClassUnique 8

we see that it has a hard-coded unique identifier. Is there a way to do the same for my own type class? Or to somehow find the Unique key dynamically?

The second challenge is more or less the same in that I want to identify a member of MyClass:

        myFunMName :: Name
        myFunMName = varQual myModule (fsLit "myFun") myFunMClassOpKey

        myFunMClassOpKey :: Unique -- How do I get this?

Again, the identifier is hard-coded for, e.g., ">>=".

Any insights will be much appreciated.

Best regards,

Jurriën_______________________________________________
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.