3
我一直在使用Haskell插件包将字符串编译为可在运行时在Haskell中使用的函数/值。但是,我遇到了一个问题:当我尝试使用相同的名称加载不同的值时,它只会给出第一个值。Haskell插件在重新编译文件时提供了旧值
这是我的测试文件:
import System.Plugins
import System.IO.Temp
import System.Directory
deleteIfExists :: String -> IO()
deleteIfExists filePath = do
exists <- doesFileExist filePath
if exists
then
(removeFile filePath)
else
(return())
compileInt :: String -> IO Int
compileInt codeMinusModule = do
withTempDirectory "./.tmp" "__compileTemp" $ \path -> do
let filePath = (path ++ "/GetInt.hs")
let code = "module GetInt where\n" ++ codeMinusModule
deleteIfExists filePath
writeFile filePath code
status <- makeAll filePath []
objectPath <-
case status of
MakeSuccess _ opath -> return opath
MakeFailure elist -> error $ "Couldn't make object:\n" ++ (concat elist)
strat <- loadInt objectPath path
deleteIfExists path
return strat
where
loadInt objectPath folderPath = do
loadStatus <- load objectPath [folderPath] [] "myInt"
case loadStatus of
LoadFailure msg -> error $ "Failed to compile " ++ (concat msg)
LoadSuccess _ strat -> return strat
而且我ghci中运行:
*Main> compileInt "myInt = 4"
Loading package array-0.4.0.1 ... linking ... done.
...
4
*Main> compileInt "myInt = 3"
4
即使当我给它一个不同的值,它使旧的。我删除了我的临时目录和所有内容。
这是插件包的固有限制,还是我做错了什么?