Legend:

* Each package has a globally-unique name, organised by some social process. This assumption is deeply built into Cabal, and lots of things would need to change if it wasn't met.

14

* '''Each package has a globally-unique name''', organised by some social process. This assumption is deeply built into Cabal, and lots of things would need to change if it wasn't met.

15

15

16

* Module names describe ''purpose'' (what it's for, e.g. {{{Data.Bits}}}), whereas package names describe ''provenance'' (where it comes from, e.g. {{{"gtkhs"}}}). We should not mix these two up, and that is a good reason for not combining package and module names into a single grand name. One quite frequently wants to globally change provenance but not purpose (e.g. compile my program with a new version of package "foo"), without running through all the source files to change the import statements.

16

* '''Module names describe ''purpose'' (what it's for, e.g. {{{Data.Bits}}}), whereas package names describe ''provenance'' (where it comes from, e.g. {{{"gtkhs"}}})'''. We should not mix these two up, and that is a good reason for not combining package and module names into a single grand name. One quite frequently wants to globally change provenance but not purpose (e.g. compile my program with a new version of package "foo"), without running through all the source files to change the import statements.

17

17

18

18

19

== Question 1: Can two different packages contain a module with the same module name? ==

19

* '''New: a module name must be unique within its package (only)'''. That is, a single program can use two modules with the same module name, provided they come from different packages. This is new in GHC 6.6. The old system (no two modules with the same name in the same program) meant that EVERY module in EVERY package written by ANYONE must have different module names. That's like saying that every function must have different local variables, and is a serious loss of modularity. Hence the change.

20

20

21

We now think that's unreasonable to answer 'no', because that means that EVERY module in EVERY package written by ANYONE must have different module names. That's like saying that every function must have different local variables, and is a serious loss of modularity. We suspect that this is something about which we can all agree.

22

23

The only sensible way to fix it is to relax the language design so that

24

25

* A module name must be unique within its package (only)

26

27

That means that module A.B.C could exist *both* in package P1 and in P2. And both packages could be linked into the same program. Suppose for the moment that A.B.C is not exposed by both P1 and P2. Then you would say simply:

28

{{{

29

ghc --make Main -o app

30

}}}

31

The authors of packages P1 and P2 didn't need to know about each other, and don't need to choose globally unique module names.

32

33

For this to work, GHC must incorporate the package name (and version) into the names of entities the package defines. That means that when compiling a module M you must say what package it is part of:

21

For all this to work, GHC must incorporate the package name (and version) into the names of entities the package defines. That means that when compiling a module M you must say what package it is part of:

* What if you want to only replace ''parts'' of P1 (e.g., you want to use an updated version of a module in {{{base}}})?

51

43

* Compiling different modules with different flags in a way that affects the ''semantics'' (rather than, say, the optimisation level) seems undesirable.

52

* To support {{{--make}}} in this situation we'd need to allow {{{-package}}} flags in the per-module {{{OPTIONS}}} pragmas, which isn't currently supported. ({{{ghc --make}}} already gathers those options together for the link step.)

44

* To support {{{--make}}} in this situation we'd need to allow {{{-package}}} flags in the per-module {{{OPTIONS}}} pragmas, which isn't currently supported. ({{{ghc --make}}} already gathers those options together for the link step.) ''This is not yet implemented, but it is close to being implemented.''

53

45

54

The obvious solution is to allow the programmer to specify the source package in the import line, something like this:

46

----------------------------

47

== Plan B: mention the package in the import ==

48

49

Another solution is to allow the programmer to specify the source package in the import line, something like this: