Haskell-如何在同一个文件中使用多个模块? [英] Haskell -- how to use multiple modules in the same file?

查看:61
本文介绍了Haskell-如何在同一个文件中使用多个模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,这是一个愚蠢的问题,但是我无法弄清楚如何将多个模块放在同一个文件中.假设文件名为 A.hs .如果我先放置模块 B ,即

Sorry this is a dumb question, but I cannot figure out how to put multiple modules in the same file. Suppose the file is named A.hs. If I put module B first, i.e.

module B where ...
module A where ...

它抱怨说,当我运行"ghci A"时,它期望的是" A "(它不是顶级的,所以我不想称其为"ghci A.hs").相反,它抱怨输入模块上的解析错误".

it complains that it expected A when I run "ghci A" (It's not top-level, so I don't want to call "ghci A.hs"). The other way around, and it complains "parse error on input module").

这里有一个相关的错误, http://hackage.haskell.org/trac/ghc/ticket/2428 .即使其他模块仅在本地使用,实际上有没有办法做到这一点?

There's a related bug here, http://hackage.haskell.org/trac/ghc/ticket/2428 . Is there actually no way to get this, even if the other module is only used locally?

推荐答案

同一文件中不能有多个模块.您链接到的错误仅与GHC给出的错误消息有关,不清楚.

You cannot have multiple modules in the same file. The bug you linked to is just about the error message given by GHC not being clear about this.

但是,如果您使用Cabal,仍然可以通过将您希望用户看到的模块放在Exposed-Modules部分中,并将所有内部模块放在Other-Modules中来控制模块的可见性.

However, if you're using Cabal, you can still control the visibility of modules by putting the modules you want visible to users in the Exposed-Modules section, and putting any internal modules in Other-Modules.

这篇关于Haskell-如何在同一个文件中使用多个模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆