Proposal: Reserved module namespace for packages on Hackage

David Menendez dave at zednenem.com
Mon Aug 18 19:32:57 EDT 2008


In the interests of reducing module name collisions, I suggest
reserving part of the module name space for individual packages on
Hackage. Specifically, I'm suggesting that a new top-level module
name, "Lib", be added to the module naming conventions, and that the
children of "Lib" be reserved for the Hackage package with the same
name. That is, "Lib.Foo" and "Lib.Foo.*" would be reserved for the
package "Foo" on Hackage.

This would not require packages to *use* this namespace. However,
packages that do use it would have a greatly reduced chance of
conflicting with other packages.

Implementation costs are minor. At most, we might want some code in
Hackage to prevent packages from using module names reserved for other
packages. At the least, all we need to do is add "Lib" to the list of
allowable top-level module names. Developers who object to giving the
provenance of a module in its name are free to take their chances with
the rest of the module hierarchy.


Mapping package names to module names is mostly straightforward.
According to the Cabal documentation, a package name consists of one
or more alphanumeric words separated by hyphens, where each word
contains at least one letter. Since hyphens aren't allowed in module
names, they would get mapped to underscores, which are not allowed in
package names. Thus, "Lib.Foo_Bar" would be reserved for package
"Foo-Bar".

It's less obvious what to do with packages whose names start with
lower-case letters or digits. I see three possible solutions:

(a) Do not reserve module names for these packages.

(b) Map these package names to module names in a way that avoids
conflicts, e.g., prefixing the package name with "P'", which cannot
occur in a package name. That is, package "foo" would get "Lib.P'foo".

(c) Change the rules for package names on Hackage by disallowing
package names which start with a digit or which differ from an
existing package only in the case of the first letter, and reserve
module names based on capitalized package names. That is, package
"foo" would get "Lib.Foo", and Hackage would not accept a new package
"Foo" if there was a preexisting "foo", and vice versa.

My preference is for (c). In fact, I might go further and forbid any
package whose name differs only in case from an existing package in
Hackage.



Further thoughts:

(1) I chose "Lib" because it's short and, so far as I know, unused.
"Hackage" might be a better choice, since the scheme depends on
Hackage to prevent name collisions.

(2) It was surprisingly difficult to find out the rules for valid
package naming. None of the tutorials I found discussed choosing a
valid name. The GHC documentation mentions that package names must
have a specific form, but I couldn't find any description of it.

(3) I did not find a definition of "alphanumeric" in the Cabal
documentation. Does this include non-ASCII characters?

(4) We could also reserve additional module names corresponding to
specific versions of packages, e.g., "Foo-1.0" might get
"Lib.Foo_1_0". This does not create ambiguity, because "Foo-1-0" is
not a valid package name.


More information about the Libraries mailing list