self-import

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Tue Jan 18 06:07:09 EST 2005


On Tue, 2005-01-18 at 10:43 +0000, Simon Peyton-Jones wrote: 
> | And if it turns out we are in the mood to look at extending the
> | inport/export/module syntax perhaps we could also consider the
> qualified
> | export idea posted a few weeks ago.
> | 
> | That was so that you could say:
> | 
> | import Graphics.UI.Gtk
> | 
> | and then use Button.setText (rather than buttonSetText) as $DEITY
> | intended. Down with the moduleNamePrefix! :-)
> 
> How would the programmer express that intent?  In the export from module
> X.Y.Button?  


module Graphics.UI.Gtk (

  -- re-export all modules (except one or two internal ones)
  module qualified Graphics.UI.Gtk.Button as Button
  ...
  -- repeat for all 121 other modules that live under Graphics.UI.Gtk.*

) where

import Graphics.UI.Gtk.Button
... etc


So that's no new keywords, no clash with existing syntax. Is the
intention clear? Maybe.

I guess the meaning is that "module qualified" exports the contents of
the module with a module qualified name, in other words it would be the
same as saying
import qualified Graphics.UI.Gtk.Button
in the module that imports Graphics.UI.Gtk, then the 'as' clause just
changes that name in the obvious way.

This looks a tad more flexible than Java's
import org.foo.bar
which just drags that part of the namespace tree closer to the root. I'm
not sure if that extra flexibility is a good thing. It might allow you
to do some counter intuitive things like re-exporting qualified names
from totally different parts of the library tree. Of course you can do
that at the moment unqualified, so maybe we just say that is bad
practise.

Duncan



More information about the Glasgow-haskell-users mailing list