I have a module Target
, with a function Target.accessMe
inside it. I compile this module in some way, then get rid of the source code.
Now, what series of arcane incantations must I do to make a different program dynamically import Target.accessMe
? This program knows accessMe
's type in advance. Also, consider the fact that the source code of Target
is not available.
The plugins
package manages to accomplish this, but seems to have serious issues with working on Windows. I've checked out plugins
's source, but am having trouble understanding it.
I've tried using Hint
, but can only find out how to evaluate code that I have the source for.
Thanks for any help!
The answer to this question has been given to me elsewhere. The GHC API is capable of doing this. Here are two functions, one of which compiles
Target.hs
, while the other accessesTarget.accessMe
(and doesn't require the source code of theTarget
module to be there anymore).That's a function that compiles a given module and returns whether compilation succeeded or not. It uses a
defaultRunGhc
helper function that is defined as:And now a function for fetching a value from the compiled module. The module's source code need not be present at this point.
And that's it!
The
plugins
package is problematic anyway. You might want to look at Hint instead.