Apply polymorphic function in a GHC plugin
I would like to write a GHC plugin which "adds a hook" to each function. Say I want to apply a function addHook
of type Ord a => (a -> b) -> a -> b
to the right-hand side of each function binding, transforming
foo = [RHS]
into
foo = addHook [RHS]
This works fine if I'm only interested in adding hooks to functions of type Int -> Int
, in which case I make addHook
also to have type (Int -> Int) -> Int -> Int
, and invoke mkCoreApp [AddHook] [RHS]
and bind it to foo
in my GHC plugin.
However, if I want addHook
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 [RHS]
Notice that there should be some type information attached, but I cannot find a way to construct these in the plugin, and GHC panics without those. Any suggestion would be appreciated.
链接地址: http://www.djcxy.com/p/7454.html上一篇: 循环键入约束
下一篇: 在GHC插件中应用多态函数