我加载了两个模块(Haskell : loading ALL files in current directory path中的外链模块NecessaryModule1.hs和NecessaryModule2.hs )。现在我想卸载NecessaryModule2.hs。然而,我在System.Plugins.Load中发现了一个“unload”函数,但它在WinGHCi中不起作用。我得到的错误消息是:
>unload NecessaryModule2
<interactive>:1:1: Not in scope: `unload'
<interactive>:1:8:
Not in scope: data constructor `NecessaryModule2'我试过了
import System.Plugins.Load但这并不管用。有没有办法以上述方式卸载模块?
对Riccardo的响应
嗨,里卡多,我试过你的建议,但我不能让它在WinGHCi中工作。我有一个文件NecessaryModule1.hs,如下所示:
module NecessaryModule1 where
addNumber1 :: Int -> Int -> Int
addNumber1 a b = a + b我通过':cd‘命令找到文件所在的位置,然后执行以下操作:
> :module +NecessaryModule1
<no location info>:
Could not find module `NecessaryModule1':
it is not a module in the current program, or in any known package.这是正确的吗?感谢编辑:请参阅下面的更正
对上面的更正
为了解释为什么上面的说法是不正确的(正如Riccardo所解释的那样),需要做的事情如下:
如果我们有如下文件NecessaryModule1.hs:
--NecessaryModule1.hs
module NecessaryModule1 where
addNumber1 :: Int -> Int -> Int
addNumber1 a b = a + b然后我们这样做:
> :load NecessaryModule1
[1 of 1] Compiling NecessaryModule1 ( NecessaryModule1.hs, interpreted )
Ok, modules loaded: NecessaryModule1.
> addNumber1 4 5
9
> :module -NecessaryModule1
> addNumber1 4 5
<interactive>:1:1: Not in scope: `addNumber1'发布于 2012-04-24 18:02:41
已安装的模块
您必须使用ghci的命令来加载(:module +My.Module)和卸载(:module -My.Module)安装的模块。您也可以使用:m而不是:module来减少代码编写,如下所示:
Prelude> :m +Data.List
Prelude Data.List> sort [3,1,2]
[1,2,3]
Prelude Data.List> :m -Data.List
Prelude> sort [3,1,2]
<interactive>:1:1: Not in scope: `sort'请记住,ghci提示符总是提醒您当前导入的模块:您可以查看一下,以便了解使用:m -Module.To.Unload卸载哪些模块。
特定文件
如果您试图加载的模块没有安装在系统中(例如,您编写了源代码并简单地将文件保存在某个地方),则需要使用不同的命令:load filename.hs。一种更快的方法是将文件的路径直接作为命令行参数传递给ghci,例如ghci filename.hs。如果运行winghci并将其与.hs扩展名关联,只需双击该文件即可。
在这两种情况下,您都会得到一个在作用域中正确加载和导入指定模块的ghci提示符(假设您没有出现get编译错误)。和以前一样,您现在可以使用:m [+/-] My.Module加载和卸载模块,但请注意,这与:load不同,因为:module假设您已经:load了您试图进入/超出作用域的内容。
例如,如果您有test.hs
module MyModule where
import Data.List
f x = sort x您可以通过双击它(在带有winghci的windows上),通过在控制台中键入ghci test.hs,或者通过加载ghci并键入:load test.hs (注意相对/绝对路径)来加载它。
另一个有用的ghci命令是:reload,它将重新编译您之前加载的模块。当您更改源文件并希望快速更新加载到ghci中的模块时,可以使用它。
Prelude> :load test.hs
[1 of 1] Compiling MyModule ( test.hs, interpreted )
Ok, modules loaded: MyModule.
*MyModule> let xs = [1,2,3] in sort xs == f xs
True
*MyModule> :reload
Ok, modules loaded: MyModule.:help将为您提供所有可用命令的完整列表。
https://stackoverflow.com/questions/10295678
复制相似问题