Hierarchical module namespace extension not sufficiently flexible

Duncan Coutts duncan.coutts at worcester.oxford.ac.uk
Fri Dec 17 09:14:48 EST 2004


All,

So here's the problem: we have a binding to a large foreign library (GTK) which
we are trying to fit nicely into hierarchical module name space. It would live under

Graphics.UI.Gtk
Graphics.UI.Gtk.Button
Graphics.UI.Gtk.Frame
... etc

Now there are over 100 modules directly under Graphics.UI.Gtk and you don't want
to have to import each one of them separately. Of course you will not use all of
them in one module but you might reasonably use 20+ of them.

So it'd be nice to be able to say:

> import Graphics.UI.Gtk
or
> import qualified Graphics.UI.Gtk as Gtk

But now we have a problem. These import directives import a flat namespace, or a
flat namespace qualified by a single module alias (ie Gtk in the second
example). But the Gtk modules are deliberatly designed to have hierarchical
names. You cannot simply combine them all together into a flat namespace without
falling back to the trick of prefixing each function name with the module name.

So while we would like to be able for users to do this:

> import Graphics.UI.Gtk
> 
> ... Button.setLabel ...

They will instead have to say:

> import Graphics.UI.Gtk
> 
> ... buttonSetLabel ...

Which is one of the things that the hierarchical module namespace extension was
trying to get rid of!

All the other language bindings for Gtk (apart from C) use the former import and
useage style. It doesn't make us look good! :-)

So my question is: have I overlooked something or is this really not possible at
the moment. And secondly, if it is currently not possible is there a 'nice'
extension that would allow this sort of thing. (Where nice probably means
Haskell98 compatible / 'doesn't' break existing programs)

How about:

> module Graphics.UI.Gtk (
> 
>   module qualified Graphics.UI.Gtk.Button as Button
>   ...
> ) where
> 
> import Graphics.UI.Gtk.Button

or equivalently(?):

> module Graphics.UI.Gtk (
>
>  module qualified Button
>  ...
> ) where
> 
> import Graphics.UI.Gtk.Button as Button


Duncan


Ps there's a oddity I found where if you say:

> module Foo (
>   module Bar
> )
> 
> import qualified Bar

then module Foo exports precisely nothing. But there's no error or warning.


More information about the Libraries mailing list