如何在提示中强制解释

发布于 2024-11-30 21:50:38 字数 706 浏览 0 评论 0原文

如何在提示(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南烟 2024-12-07 21:50:38

使用-fforce-recomp选项在从 GHCi/Hint 使用时似乎会强制解释。

unsafeSetGhcOption "-fforce-recomp"

虽然我找不到任何文档来验证这一点,但 GHCi/Hint 重用 GHC 的重新编译检查似乎是合理的。


更新:进一步挖掘,我发现GHC Ticket #2542< /a>,其中指出在模块名称前添加星号将强制在 GHCi 中进行解释。
文档也证实了这一点。

:load *test.hs

这似乎也适用于 Hint,所以这也有效:

loadModules ["*" ++ mname ++ ".hs"]

Using the -fforce-recomp option seems to force interpretation when used from GHCi/Hint.

unsafeSetGhcOption "-fforce-recomp"

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.

:load *test.hs

This appears to carry over to Hint as well, so this also works:

loadModules ["*" ++ mname ++ ".hs"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文