[Haskell] Re: Hierarchical module namespace extension not sufficiently flexible

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Mon Mar 7 05:55:23 EST 2005

On Mon, 2005-03-07 at 17:39 +1100, Andre Pang wrote:
> On 06/03/2005, at 11:23 PM, Duncan Coutts wrote:
> > We can do it too except that to use qualified names, users would have 
> > to
> > import dozens of modules:
> > import Graphics.UI.Gtk.This
> > import Graphics.UI.Gtk.That
> > import Graphics.UI.Gtk.TheOther.
> Not that this is a fantastic solution (and perhaps you're doing this 
> already), but one technique is to make a module named Graphics.UI.Gtk 
> (i.e. Graphics/UI/Gtk.hs), which imports all the submodules for you and 
> re-exports all of them:

Yes indeed that is what we do.

The disadvantage of doing this over importing each module individually
(which we do not encourage as it's impractical) is that now one must
export a flat namespace but Gtk+ is not a flat namespace!

When you import each module individually you can import qualified:

        import qualified Graphics.UI.Gtk.Button as Button
and then use:

But since we use
        import Graphics.UI.Gtk
then you can only use 'label' or 'Gtk.label' but that does not
distinguish between the different Gtk+ modules which use 'label'.

So sadly we have to prefix the module name to each exported entity so
you say for example:
        button <- buttonNew
        buttonSetLabel button "bla"

Of course what we would like to be able to do the imports/exports such
that users can say:
        button <- Button.new
        Button.setLabel button "bla"
or if using the Yahu-style interface it'd be:
        button <- Button.new [Button.label := "bla"]


More information about the Haskell mailing list