[Haskell-cafe] Design your modules for qualified import

Isaac Dupree isaacdupree at charter.net
Mon Jun 16 08:02:10 EDT 2008


Duncan Coutts wrote:
> Right. That's exactly why we've not done something like that. With 100+
> modules in the Gtk package it's totally infeasible to do qualified
> imports of them all.
> 
> If we get a proper way to export a non-flat namespace then Gtk2Hs will
> certainly switch to using it. Using 'buttonBlah' is horrible but there
> is currently nothing better.

okay, it's horrible!  It's no more manually-traceable than anything else 
either, if you just import Gtk2Hs unqualified.  Is there any way it 
could possibly be acceptably concise *and* traceable? let's see

If "GTK" appears in every usage (e.g. GTK.buttonBlah, gtkButtonBlah...), 
probably not at all concise enough for GUI code!  But if it doesn't, 
then we would need at minimum to list each of those ones that we used 
(probably not all 100 of them).  It couldn't get any more concise than 
this to use Button.blah etc.:

import GTK.modules (Button, Window, ...)

never mind the exact syntax yet -- is listing them acceptable? (and if 
there are so many, is it practically traceable by humans anyway? 
Perhaps we're assuming that these humans at least have "search this 
file" editor-capabilities?)

Are there multiple "blah" functions among the GTK modules? I.e. would 
GTK.blah be unambiguous, not mentioning that it's a button function. 
(And would it be too confusing not to mention that it's a button 
function...)  If it would be ambiguous, would typeclasses work to fix 
that (or renaming functions that have no good reason to have the same 
name, or occasionally including blahButton sort of names)?

If 100 modules is too much, would it be a reasonable compromise between 
clarity and conciseness to export coarser-grained, so there are only 
maybe half a dozen GTK modules that your typical program imports?

> There have been a few suggestions along these lines. Check the archives.
> I'm not sure what is proposed for haskell', probably nothing since
> nothing is currently implemented and we're only supposed to be
> standardising existing practise.

I had trouble in my first attempt to search the archives... Googling for 
"import" in haskell-cafe found too much code, and my personal e-mail 
records back to March 2007 found nothing else relevant with "import" in 
the title.

-Isaac


More information about the Haskell-Cafe mailing list