再出口合格? [英] Re-export qualified?
问题描述
假设您有两个模块,例如
模块Foo.A其中
foo = 42
和
module Foo.B其中
foo = 12
和你想要写一个超级模块
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ module $ F $.
)其中
进口Foo.A
进口Foo.B
这是重新导出这些模块,你会得到一个名称冲突。
有没有解决方案?
基本上没有。这一直是Gtk2hs的作者们长期以来的特征要求。 Gtk2hs有一个非常广泛的模块层次结构,它可能对两种模式都有意义:
- 在几个不同的模块中使用相同的名称(例如newButton Graphics.UI.Gtk.Buttons.Button和Graphics.UI.Gtk.Buttons.CheckButton)
- 为使用单个导入语句导入所有这些模块的用户提供方便 >
现在,如果您想将多个模块重新导出到一起,您只需要完成以下操作:
suppose you have two modules like
module Foo.A where
foo = 42
and
module Foo.B where
foo = 12
and you want to write a super module
module Foo (
module Foo.A
, module Foo.B
) where
import Foo.A
import Foo.B
which re-exports those modules, you would get a name clash.
Is there a solution for this?
Basically, no. This has been a long-standing feature request by people like the authors of Gtk2hs. Gtk2hs has a very broad module hierarchy where it might make sense to both:
- Use the same name in several different modules (e.g. newButton in both Graphics.UI.Gtk.Buttons.Button and Graphics.UI.Gtk.Buttons.CheckButton)
- Provide the convenience to the user of importing all these modules with a single import statement
For now, if you want to reexport several modules together all you can do is:
- Avoid reusing names in the modules you wish to reexport
- Where appropriate, use type classes to allow the same name to be used for several different purposes
这篇关于再出口合格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!