[Haskell-cafe] Is it possible to export module aliases?

Brian Hulley brianh at metamilk.com
Wed Apr 26 21:51:21 EDT 2006

Hi -
Given some large list of modules which need to be used qualified, I'd like 
to be able to make a convenience module that I could use instead, and which 
would export all these modules also qualified by an alias, ie:

module Top
       ( module qualified Top.First as First
       , module qualified Top.Second as Second
       ) where ...
import qualified Top.First

so that I could then say:

import Top

main = do
   a <- First.create ...
   b <- Second.create ...

instead of having to always write:

import qualified Top.First as First
import qualified Top.Second as Second
-- this may be a *very* long list

in every module that uses the "Top" API.

The current "workaround" for this problem in the standard libraries seems to 
be to always append the module name to the name of the function or type or 
constructor (which is unfortunately, like record field names, not local to 
the type but that's another story) eg by using createFirst, createSecond 
etc, which seems a bit messy to me.

An alternative is to use the C preprocessor and #include a file containing 
all the import declarations, but although "ok", I'd prefer to be able to 
express the code organization purely in Haskell itself.

This must be a very common issue so I'm wondering if anyone else has some 
better ideas on how to solve it?

Thanks, Brian. 

More information about the Haskell-Cafe mailing list