Haskell:加载当前目录路径中的所有文件 [英] Haskell : loading ALL files in current directory path
问题描述
命令(在GHCi中)
:load abc
加载文件abc中的函数(它必须存在于当前目录路径中)。我将如何加载当前目录路径中的所有文件?谢谢
---------------------------------- ------------------------------------------------
[b
]
嗨Rotskoff,谢谢我尝试了你的建议,但是我无法完成它的工作,所以我想我一定误解了一些东西。我创建了3个文件test.hs,test1.hs和test2.hs,如下所示:
- >
- test.hs
import必需模块
- >
- test1.hs
module NecessaryModule其中
addNumber1 :: Int - > Int - > Int
addNumber1 ab = a + b
- >
- test2.hs
module NecessaryModule其中
addNumber2 :: Int - > Int - > Int
addNumber2 ab = a + b
然后当我这样做时:
:load test
我得到了错误信息:
test.hs:1:8:
找不到模块`NecessaryModule' :
使用-v查看搜索的文件列表。
感谢
----- -------------------------------------------------- --------------------------
谢谢。这是我为了让它起作用而做的(按照Rotskoff的建议):
- >
- test.hs
import NecessaryModule1
import NecessaryModule2
- >
- 必要模块1.hs
addNumber1 :: Int - > Int - > Int
addNumber1 ab = a + b
- >
- NecessaryModule2.hs
addNumber2 :: Int - > Int - > Int
addNumber2 ab = a + b
推测你的意思是Haskell源文件,因为你不能在GHCi中使用:load
命令来做其他事情。
在您加载的源文件的顶部,包含以下行:
import NecessaryModule
对于每个源文件,请确保命名模块,例如
$应该出现b $ b
module NecessaryModule其中
。 GHCi将自动链接所有文件。
如果您要导入数据,请查看 System.Directory
在文档中。
The command (in GHCi)
:load abc
Loads the functions in the file abc (which must exist in the current directory path). How would I load all the files in the current directory path? Thanks
----------------------------------------------------------------------------------
[RESPONSE TO POST BELOW]
Hi Rotskoff, thanks I tried your suggestion but I could not get it to work, so I think I must have misunderstood something.
I created 3 files test.hs, test1.hs, and test2.hs as follows :
->
--test.hs
import NecessaryModule
->
--test1.hs
module NecessaryModule where
addNumber1 :: Int -> Int -> Int
addNumber1 a b = a + b
->
--test2.hs
module NecessaryModule where
addNumber2 :: Int -> Int -> Int
addNumber2 a b = a + b
Then when I did :
:load test
I got the error message :
test.hs:1:8:
Could not find module `NecessaryModule':
Use -v to see a list of the files searched for.
Thanks
---------------------------------------------------------------------------------
Thanks. This is what I did to get it to work (following Rotskoff's suggestion) :
->
--test.hs
import NecessaryModule1
import NecessaryModule2
->
--NecessaryModule1.hs
addNumber1 :: Int -> Int -> Int
addNumber1 a b = a + b
->
--NecessaryModule2.hs
addNumber2 :: Int -> Int -> Int
addNumber2 a b = a + b
Presumably you mean Haskell source files, because you can't use the :load
command in GHCi for anything else.
At the top of the source file that you load, include the line:
import NecessaryModule
For each of the source files, make sure to name the modules, e.g.,
module NecessaryModule where
should appear. GHCi will automatically link all the files.
If you're trying to import data, take a look at System.Directory
in the documentation.
这篇关于Haskell:加载当前目录路径中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!