再出口合格? [英] Re-export qualified?

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

问题描述

假设您有两个模块,例如

 模块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)

  • 为使用单个导入语句导入所有这些模块的用户提供方便
  • >


现在,如果您想将多个模块重新导出到一起,您只需要完成以下操作:


  • 避免在要重新输出的模块中重复使用名称

  • 在适当的情况下,使用类型类别可以将相同的名称用于多种不同的目的
  • li>

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屋!

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