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

J. Stutterheim j.stutterheim at me.com
Fri Nov 18 08:36:44 UTC 2016


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3117 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161118/4408327b/attachment.bin>


More information about the Haskell-Cafe mailing list