I have an application where, for various reasons, I need to run arbitrary, user supplied code. (SafeHaskell makes this nice and secure). I've looked at the plugins package, which is really nice for loading from a .hi file on disc.
However, for my program design, it would be ideal if I could store these user programs in a database, then directly compile them to functions which I can use in my program.
So, if the function I'm compiling has the following type:
someFunction :: MyIn -> MyOut
I'm looking to write some function that will generate that function from a string:
hotCompile :: String -> IO (MyIn -> MyOut)
where string contains the haskell code code for "someFunction".
Does anybody know if there's a way to do this, preferably using the plugins package? I have come across the GHC API a little bit, but I don't know much about it and how it would relate to this.
Note that I've tried hint, but it is unsuitable for my application because it is not threadsafe.
.hi
files in a database? At worst you could base64 encode it and store it as a string that way. – Southinghint
package. I'll find time to give an answer if someone else doesn't by tomorrow. – Canovahint
(and any other solutions you have tried) – Outfieldhint
isn't thread-safe, despite the claims to the contrary in its documentation - and that's entirely because the ghc api it relies on isn't thread-safe. – Souvaine