Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell:卸载WinGHCi中的模块_Haskell_Ghc_Ghci_Winghci - Fatal编程技术网

Haskell:卸载WinGHCi中的模块

Haskell:卸载WinGHCi中的模块,haskell,ghc,ghci,winghci,Haskell,Ghc,Ghci,Winghci,我加载了两个模块(如中所示的NecessaryModule1.hs和NecessaryModule2.hs)。现在我想卸载必需的module2.hs。然而,我在中发现了一个“unload”函数,但它在WinGHCi中不起作用。我收到的错误消息是: >unload NecessaryModule2 <interactive>:1:1: Not in scope: `unload' <interactive>:1:8: Not in scope: data

我加载了两个模块(如中所示的NecessaryModule1.hs和NecessaryModule2.hs)。现在我想卸载必需的module2.hs。然而,我在中发现了一个“unload”函数,但它在WinGHCi中不起作用。我收到的错误消息是:

>unload NecessaryModule2

<interactive>:1:1: Not in scope: `unload'

<interactive>:1:8:
    Not in scope: data constructor `NecessaryModule2'
但这并不奏效。是否有办法以上述方式卸载模块

--------------------------------------------------------------------------------------- [对里卡多的答复]


嗨,Riccardo,我试过你的建议,但我在WinGHCi没能奏效。我有一个文件NecessaryModule1.hs,如下所示:

module NecessaryModule1 where

addNumber1 :: Int -> Int -> Int
addNumber1 a b = a + b
--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.
然后我们做:

> :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'
>:加载必要模块1
[1/1]编译必要模块1(必要模块1.hs,已解释)
好的,模块已加载:必需模块1。
>地址号码14 5
9
>:模块-必要模块1
>地址号码14 5
:1:1:不在范围内:`addNumber1'

已安装的模块

您必须使用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'
您可以通过双击它(在带有winghci的窗口上)、在控制台中键入
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
将为您提供所有可用命令的完整列表。

你好,Riccardo,我尝试了您的建议,但遇到了一些问题。我已经在上面发布了,因为这里的空间太小了。谢谢Riccardo,非常感谢你解释得很好的回答。我真的很感谢你花时间把这些写出来。谢谢。
:m-Data.List
可以工作,但它不适用于前奏曲。有什么办法可以卸下序曲?
module MyModule where
import Data.List

f x = sort x
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.