Fwd: Type/type class information in GHC plugin

Shen Chen Xu shenchenxu at gmail.com
Thu Apr 24 21:37:25 UTC 2014

Hello everyone,

I would like to write a GHC plugin which adds wrapper to functions. Say I have
a function

addWrapper :: Ord a => (a -> b) -> a -> b

which is supposed to transform (assuming the argument is in the Ord class)

foo = \ x -> ...


foo = addWrapper (\ x -> ...)

This works fine if I'm only interested in wrapping functions of type Int ->
Int, in which case I make addWrapper to also have type

addWrapper :: (Int -> Int) -> Int -> Int

and use mkCoreApp to apply addWrapper to the right hand side.

However, if I want it to be polymorphic as described above, the transformed GHC
Core for an Int -> Int function should look like

foo = addHook @ GHC.Types.Int @ GHC.Types.Int GHC.Classes.$fOrdInt (\ x -> ...)

My question is, given the right hand side of foo, how do I construct the
type/type class information inside Core shown above?


More information about the Glasgow-haskell-users mailing list