Haskell:加载当前目录路径中的所有文件(Haskell : loading ALL files in current directory path)

编程入门 行业动态 更新时间:2024-10-10 17:25:42
Haskell:加载当前目录路径中的所有文件(Haskell : loading ALL files in current directory path)

命令(在GHCi中)

:load abc

-------------------------------------------------- --------------------------------

[对下文的回复]

嗨Rotskoff,谢谢我尝试了你的建议,但是我无法完成它的工作,所以我想我一定误解了一些东西。

我创建了3个文件test.hs,test1.hs和test2.hs,如下所示:

- >

--test.hs import NecessaryModule

-------------------------------------------------- -------------------------------

谢谢。 这是我为了让它工作而做的(遵循Rotskoff的建议):

- >

--test.hs import NecessaryModule1 import NecessaryModule2

----------------------------------------------------------------------------------

[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

---------------------------------------------------------------------------------

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

最满意答案

推测你的意思是Haskell源文件,因为你不能在GHCi中使用:load命令来做其他事情。

在加载的源文件的顶部,包含以下行:

import NecessaryModule

对于每个源文件,确保命名模块,例如,

module NecessaryModule where

应该出现。 GHCi会自动链接所有文件。

如果您要导入数据,请查看文档中的System.Directory 。

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.

更多推荐

本文发布于:2023-07-27 02:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1284023.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   加载   文件   目录   Haskell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!