开发者

How do I force interpretation in Hint

开发者 https://www.devze.com 2023-03-29 08:57 出处:网络
How do I force interpretation mode in Hint (Language.Haskell.Interpreter)? I have this code: module Main where

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 <- 开发者_JAVA技巧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")


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"]
0

精彩评论

暂无评论...
验证码 换一张
取 消