[Haskell-cafe] GHC plugin: custom wired-in package, module, and type class

Amos Robinson amos.robinson at gmail.com
Fri Nov 18 23:04:23 UTC 2016

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.


On Fri, 18 Nov 2016 at 19:36 J. Stutterheim <j.stutterheim at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161118/02b48833/attachment.html>

More information about the Haskell-Cafe mailing list