Haskell:一次只能通过:load加载一个文件 [英] Haskell : can only load one file at a time via :load

查看:82
本文介绍了Haskell:一次只能通过:load加载一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个模块NecessaryModule1&NecessaryModule2(如帖子中概述的那样:Haskell:将所有文件加载到当前目录路径中.然后我在WinGHCi和GHCi中都注意到,如果这样做:

suppose I have two modules NecessaryModule1 & NecessaryModule2 (as outlined in the post Haskell : loading ALL files in current directory path. Then I have noticed in both WinGHCi and GHCi that if I do :

> :load NecessaryModule1
[1 of 1] Compiling NecessaryModule1 ( NecessaryModule1.hs, interpreted )
Ok, modules loaded: NecessaryModule1.
> addNumber1 2 3
5
> :load NecessaryModule2
[1 of 1] Compiling NecessaryModule2 ( NecessaryModule2.hs, interpreted )
Ok, modules loaded: NecessaryModule2.
> addNumber1 2 3

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

即加载NecessaryModule2会消除NecessaryModule1中的所有功能.

i.e. loading NecessaryModule2 eliminates all the functions from NecessaryModule1.

这是否意味着我可以同时加载NecessaryModule1&NecessaryModule2是否要使用第三个文件(同时导入NecessaryModule1和NecessaryModule2),然后加载该第三个文件?(例如,请参见 Haskell中的test.hs:在当前目录路径中加载所有文件)谢谢.

So does that mean that the only way I can simultaneously load NecessaryModule1 & NecessaryModule2 is to use a third file (which imports both NecessaryModule1 & NecessaryModule2) and then load that third file? (e.g. see test.hs in Haskell : loading ALL files in current directory path) Thanks.

[对怪兽的反应]

所以,如果我已经完成:load NecessaryModule1 ,然后我想在MyMod.hs中加载模块:

Hi, so if I have done :load NecessaryModule1 and then I want to load the module in MyMod.hs :

--MyMod.hs
module MyMod where
import Data.List

f x = sort x

那我该怎么做?在 Haskell中:WinGHCi中的卸载模块 Riccardo解释说:module 假定模块已经加载.那么这是否意味着实现加载多个自定义模块的唯一方法是通过调用:load 函数来加载它们?谢谢.

then how would I do this? In Haskell : unload module in WinGHCi Riccardo explains that :module assumes that the modules have already been loaded. So does this mean that the only way to achieve the loading of multiple custom modules is to load them with a single call of the :load function? Thanks.

推荐答案

好,有两点要考虑:什么是:module"知道要找到的,以及在给定提示下上下文中实际上是什么.

Ok, there are two things to consider : what ":module" know to find, and what is actually in context at a given prompt.

:module总是知道如何在已安装的软件包(未隐藏)中查找模块,默认情况下,这就是它可以访问的全部.但是您可以使用:load使它知道特定文件中的其他模块.每次调用:load都会重置其他模块集(和:reload保留相同的加载模块集,但会刷新其内容).另外:load将您带入您指定的第一个模块的上下文中.

:module always know how to find modules in installed packages (that are not hidden) and by default that's all that it has access to. But you can use :load to make it aware of some other modules in specific files. Each call of :load reset the set of additional modules (and :reload keep the same set of loaded module but refresh their content). Also :load put you into the context of the first module you specify.

换句话说,如果您想进入两个模块都导入的上下文,则需要执行以下操作:

In other word, if you want to get into a context where both modules are imported, you need to do :

> :load Module1 Module2
> :module Module1 Module2

那么这是否意味着实现加载多个自定义模块的唯一方法是通过:load函数的一次调用来加载它们?

So does this mean that the only way to achieve the loading of multiple custom modules is to load them with a single call of the :load function?

换句话说:是的!(但这似乎不成问题,只是如果您仍想在新的上下文中使用它们,则需要重复以前加载的模块)

In other words : yes ! (but that doesn't seem to be a problem except that you need to repeat modules you loaded in the past if you still want to use them in the new context)

这篇关于Haskell:一次只能通过:load加载一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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