Haskell 中的多个源文件

Igo*_*gor 6 haskell compilation ghci

我正在用 Haskell 编写我的第一个大项目,我想将它拆分到多个文件中。到目前为止,我已经编写了两个模块,Parse以及Eval. 我想要一个Main只包含这两个模块并指定main功能的模块。我有文件Main.hsParse.hsEval.hs并将它们导入Main,但会发生这种情况:

Prelude> :load "~/code/haskell/lisp/Main.hs"
[1 of 3] Compiling Eval             ( Eval.hs, interpreted )
[2 of 3] Compiling Parse            ( Parse.hs, interpreted )
[3 of 3] Compiling Main             ( ~/code/haskell/lisp/Main.hs, interpreted )
Ok, modules loaded: Main, Parse, Eval.
*Main> parse parseExpr "" "#b101"

<interactive>:1:0: Not in scope: `parse'
Run Code Online (Sandbox Code Playgroud)

parse函数来自 Parsec 库,该库以Parse.hs. 怎么了?

Tra*_*own 5

来自Haskell 报告

模块实现只能导出它声明的实体,或者从其他模块导入的实体。如果省略导出列表,则导出模块中定义的所有值、类型和类,但不导出导入的值、类型和类。

您要么需要提供包含parsein的显式导出列表Parse.hs,要么parse在您的Main.hs.