tags:

views:

60

answers:

1

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

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

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.

Is there any way to make GHC export these modules?

+2  A: 

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.

Yitz
But it's possible to re-export qualified symbols; for example, `import qualified Foo.B` will let me do `module Foo.A ( Foo.B.sym )`. Why isn't this possible with modules?I'm not exporting two symbols with the same name; anything conflicting is internal to the module.
John Millikin