为什么不能在提示中将顶层模块设置为主要模块 [英] Why cannot top level module be set to main in Hint

查看:172
本文介绍了为什么不能在提示中将顶层模块设置为主要模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不能在提示(Language.Haskell.Interpreter)中将顶层模块设置为Main?

允许我演示:

 模块Main其中

import Language.Haskell.Interpreter
导入Control.Monad

main = do
res< - runInterpreter(testtest)
case $ res
Left e - > putStrLn(显示e)
右t - > putStrLn(show t)
return()

test :: String - > Interpreter()
test mname =
do
loadModules [mname ++.hs]
setTopLevelModules [Main]

$ b $>
$ b>
$ b 将导致:

  NotAllowed这些模块不解释:\主要\


解决方案

正如 the文档说,顶级模块必须解释,即不编译。



加载模块时,如果可用,将使用编译版本。 GHCi手册有更详细的信息这个。



我猜测有一个 test.o test.hi 在早期版本的相同文件夹中。我能够用这些文件重现错误。删除它们可以解决问题,因为模块将被解释。



您还可以强制模块在解释模式下加载,方法是在模块名称前面加星号,例如 loadModules [*++ mname ++.hs]


Why cannot top level module be set to "Main" in Hint (Language.Haskell.Interpreter)?

Allow me to demonstrate:

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:

NotAllowed "These modules are not interpreted:\nMain\n"

解决方案

As the documentation says, top level modules have to be interpreted, i.e. not compiled.

When loading a module, a compiled version will be used if it's available. The GHCi manual has more detailed information on this.

I'm guessing there's a test.o and test.hi in the same folder from an earlier build. I was able to reproduce the error with these files present. Deleting them solves the problem, as the module will then be interpreted.

You can also force a module to be loaded in interpreted mode by prefixing the module name with an asterisk, e.g. loadModules ["*" ++ mname ++ ".hs"].

这篇关于为什么不能在提示中将顶层模块设置为主要模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆