如何在提示中强制解释
如何在提示(Language.Haskell.Interpreter)中强制解释模式?
我有这段代码:
module Main where
import Language.Haskell.Interpreter
import Control.Monad
main = do
res <- runInterpreter (test "test")
case res of
Left e -> putStrLn (show e)
Right t -> putStrLn (show t)
return ()
test :: String -> Interpreter ()
test mname =
do
loadModules [mname ++ ".hs"]
setTopLevelModules ["Main"]
将导致(基于此处的答案):
NotAllowed "These modules are not interpreted:\nMain\n"
仅当 GHC 找到 test.o!
我试过了
unsafeSetGhcOption ("-fbyte-code")
How do I force interpretation mode in Hint (Language.Haskell.Interpreter)?
I have this code:
module Main where
import Language.Haskell.Interpreter
import Control.Monad
main = do
res <- runInterpreter (test "test")
case res of
Left e -> putStrLn (show e)
Right t -> putStrLn (show t)
return ()
test :: String -> Interpreter ()
test mname =
do
loadModules [mname ++ ".hs"]
setTopLevelModules ["Main"]
Will result in (based on the answers from here):
NotAllowed "These modules are not interpreted:\nMain\n"
only if GHC finds test.o!
I've tried
unsafeSetGhcOption ("-fbyte-code")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
-fforce-recomp
选项在从 GHCi/Hint 使用时似乎会强制解释。
虽然我找不到任何文档来验证这一点,但 GHCi/Hint 重用 GHC 的重新编译检查似乎是合理的。
更新:进一步挖掘,我发现GHC Ticket #2542< /a>,其中指出在模块名称前添加星号将强制在 GHCi 中进行解释。
文档也证实了这一点。
这似乎也适用于 Hint,所以这也有效:
Using the
-fforce-recomp
option seems to force interpretation when used from GHCi/Hint.Although I could not find any documentation to verify this, it seems reasonable that GHCi/Hint would reuse the recompilation checking from GHC.
UPDATE: Digging around a bit more I found GHC ticket #2542, where it is stated that prefixing the module name with an asterisk will force interpretation in GHCi.
This is also confirmed in the documentation.
This appears to carry over to Hint as well, so this also works: