gpt4 book ai didi

haskell - 从当前工作目录导入模块

转载 作者:行者123 更新时间:2023-12-03 09:57:03 25 4
gpt4 key购买 nike

init.hs库模块有,

module init where
data Suite = Clubs | Diamonds | Hearts | Spades deriving (Eq,Ord,Enum,Show)

main.hs,入口模块有,
module Main where
import init
main = do
print (fromEnum Clubs)

两个模块都在同一个目录中,并且该目录不是 cabal 路径的一部分。

在做 runhaskell main.hs ,它会抛出错误为 main.hs:2:8: parse error on input ‘init’ .

在不污染全局 PATH/CABAL 变量的情况下,在当前工作目录中导入模块的正确方法是什么?

最佳答案

模块名称不应该以大写字母开头吗?
替换 initInit :

module Init where
data Suite = Clubs | Diamonds | Hearts | Spades deriving (Eq,Ord,Enum,Show)
module Main where
import Init
main = do
print (fromEnum Clubs)

编辑:
正如 ØrjanJohansen 所述:

Usually, the file should be named after the module name, replacing dots in the module name by directory separators.



Quote source

在你的情况下 Init.hs应该使用。

关于haskell - 从当前工作目录导入模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31665573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com