GHC拒绝出口合格模块 [英] GHC refuses to export qualified modules

查看:57
本文介绍了GHC拒绝出口合格模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个模块,该模块可以重新导出其已导入合格的某些模块.像这样:

I want to write a module which re-exports some module it had imported qualified. Something like this:

module Foo.A
  ( module Foo.B
  , module Foo.C
  ) where
import qualified Foo.B
import qualified Foo.C

-- bunch of code using Foo.B and Foo.C here

这似乎应该起作用;但是,GHC会打印有关出口的警告:

This looks like it ought to work; however, GHC prints warnings about the exports:

Foo/A.hs:2:5:
    Warning: the export item `module Foo.B' exports nothing

Foo/A.hs:3:5:
    Warning: the export item `module Foo.C' exports nothing

GHCI拒绝加载它们的出口.

And GHCI refuses to load exports from them.

我可以通过使导入不合格来解决此问题,但是这些导入与主模块代码之间可能会发生命名冲突.

I can solve this by making the imports unqualified, but then naming conflicts are likely to arise between those imports and the main module code.

有什么方法可以使GHC导出这些模块吗?

Is there any way to make GHC export these modules?

推荐答案

不,这不仅仅是GHC的限制,而是导入的方式 并且导出功能可以在Haskell中使用.

No, that isn't just a limitation of GHC, it's the way import and export is designed to work in Haskell.

一个模块只有一个 控制自己的名称空间-它不会影响人们 可以从其他名称空间看到.一个模块 再出口"只是说全部出口 我自己的命名空间中恰好有 是从另一个模块中导入的."但是符号 您进口的合格品并不是您自己真正拥有的 命名空间.

A module only has control of its own namespace - it can't affect what people can see from other namespaces. A module "re-export" is just a shorthand to say "export all of the symbols in my own namespace that happen to have been imported here from that other module". But symbols that you imported qualified aren't really in your own namespace.

如果要导出两个不同的符号 相同的名称,您将无法通过一个模块来做到这一点. 将模块分成两部分,然后从中导出每个版本 一个不同的模块.

If you want to export two different symbols that have the same name, you won't be able to do it from one module. Split the module into two, and export each version from a different module.

这篇关于GHC拒绝出口合格模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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