对不起,这是一个愚蠢的问题,但我无法弄清楚如何将多个模块放在同一个文件中.假设该文件名为A.hs.如果我把模块B放在第一位,即
module B where ...
module A where ...
Run Code Online (Sandbox Code Playgroud)
当我跑"ghci A"时,它抱怨它预期A(它不是顶级的,所以我不想打电话给"ghci A.hs").反过来说,它抱怨"输入模块上的解析错误").
这里有一个相关的错误,http://hackage.haskell.org/trac/ghc/ticket/2428.实际上没有办法得到这个,即使其他模块只在本地使用?
ham*_*mar 23
您不能在同一文件中包含多个模块.您链接的错误只是GHC给出的错误消息,不清楚这一点.
但是,如果您使用的是Cabal,您仍然可以通过将要显示的模块放入该Exposed-Modules部分中的用户并将任何内部模块放入其中来控制模块的可见性Other-Modules.
小智 8
我发现了以下错误报告.
这是指这个邮件列表项,其中指出:
No, that's not possible because haskell will use the module name A.B.C to look the module up in path A/B/C.[l]hs.
So using modules
module A where
..
module B where
the compiler could only find one of them. (naming the file A.hs or B.hs)
You have to use one file for each module
Run Code Online (Sandbox Code Playgroud)
所以,我猜答案是否定的.