[Haskell-cafe] Design your modules for qualified import
Sebastian Sylvan
sebastian.sylvan at gmail.com
Mon Jun 9 16:53:28 EDT 2008
On Thu, Jun 5, 2008 at 4:19 PM, Johan Tibell <johan.tibell at gmail.com> wrote:
>
>
> * Why is this practice common in Haskell
>
> Here are some guesses:
>
> 1. It's common in papers. However, papers and libraries are quite
> different. The former usually build up a small vocabulary and having
> short names is a big win. Papers rarely make use of the module system
> at all. The latter are included as pieces of large programs and their
> names need to be adjusted accordingly.
>
> 2. It's the default. You have to add "qualified" to all your imports
> to make them qualified. In most language imports are qualified by
> default. I think the latter would have been a better choice but we
> have to live with the current design so bite the bullet and add those
> qualified keywords to your imports.
>
> 3. Lack of common interfaces. An example would be two different set
> implementations that essentially have the same interface but since
> there is no explicitly shared interface, defined using a type class,
> you sometimes end up with different names. The lack of type families
> might explain why e.g. collection classes don't share interfaces.
>
> 4. Haskell is a very expressive language. You can often write a whole
> function definition on one line! Adding those module qualifications
> makes your code slightly longer and it might just break your beautiful
> one liner into two lines.
>
Another BIG reason: It's impossible to export a whole hierarchy qualified.
I.e it would be neat if the user could write:
import Graphics.UI.Gtk
And then have Gtk re-export sub-modules qualified, so you could write
"Button.new", "Window.new" etc. etc. As it stands you have two options:
prefix all the "new" functions with the kind of widget they create
(buttonNew, windowNew), or force the user to add a gazillion qualified
imports.
Ideally you would be able to add "qualified" to the module export statement,
and have it automatically bring in that module qualified (it should also
support an "as" so you'd write "qualified module Graphics.UI.Gtk.Button as
Button" in the export list to get the above behaviour.)
--
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080609/167e1039/attachment-0001.htm
More information about the Haskell-Cafe
mailing list