[Haskell] RE: package mounting

Simon Peyton-Jones simonpj at microsoft.com
Mon Oct 30 17:58:00 EST 2006

[narrowing to libraries]

| > I think most of you know that GHC 6.6 made (IHMO) a significant step
| > forward, by allowing a program to contain multiple modules with the
| > name, if they are from different packages.  That means that package
| > authors can choose module names freely, rather than worry about
| > accidentally colliding with other packages.
| I think this is true only in a very technical sense. I fear that in
| practice, library authors will go to great lengths to avoid such
| overlapping module names, because introducing them will cause too much
| difficulties for library users. The only way to make halfway sure that
| doesn't happen is to use (fixed) module hierarchy prefixes containing
| or less) the package name, as in "Text.ParserCombinators.Parsec", even
| though technically they aren't forced to do so.

Why would authors go to great lengths to avoid overlapping module names?
The only possible penalty of overlap is that it's a bit awkward to
import modules with the same name into the same module.  But that's
always fixable by making a two-line impedance-matching module.

I feel I'm missing your point.

| I see, however, one point with Frederik's proposal that isn't clear to
| Assume library A uses library B. Then, presumably, lib A must chose a
| point for its use of lib B. Now imagine a program P wants to use lib A
| well as directly import some module from lib B. Is P now free to give
lib B
| its own mount point, independent of the one that was chosen by lib A?

Oh yes, of course!  The mount point simply affects the name space seen
by the import declarations in a particular compilation.  There is no
implementation difficulty here.

| > That still leaves an open question, not resolved by GHC 6.6: what to
| > if you want to import module M from two different packages into the
| > module?
| What if I want to import them into /different/ modules (which are
| nevertheless part of the same package)? Can this be easily
| with ghc-6.6?

Yes, certainly.  Suppose that package 'foo' and 'bar' both contain
module M.  Then you want to import foo.M into module X, and bar.M into
module Y.  Easy: just compile X with '-package foo' and Y with '-package
bar'.  The difficulty arises only if you want to import foo.M and bar.M
into the *same* module.

Indeed, the difference between Plan B and C (in the terminology of the
GhcPackages page) is only whether you say

	ghc X.hs -package foo -package bar
	module X
	  import M from "foo"
	  import M from "bar"

or whether you say

	ghc -package foo at Foo -package bar at Bar X.hs
	module X
	  import Foo.M
	  import Bar.M

The two are really very close --- but the nuances are different and they
are important.


More information about the Libraries mailing list