Changes between Version 31 and Version 32 of Commentary/Packages/GhcPackagesProposal


Ignore:
Timestamp:
Oct 4, 2006 1:29:20 PM (8 years ago)
Author:
simonpj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Packages/GhcPackagesProposal

    v31 v32  
    1212 
    1313Before we start, note that we take for granted the following 
    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. 
     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. 
    1515 
    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. 
    1717 
    1818 
    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. 
    2020 
    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: 
     21For 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: 
    3422{{{ 
    3523  ghc -c -package-name P1 C.hs 
     
    3725Then C.o will contain symbols like "{{{P1.A.B.C.f}}}" etc.  In effect, the "original name" of a function {{{f}}} in module {{{M}}} of package {{{P}}} is {{{<P,M,f>}}}. 
    3826 
    39 But what if two packages '''expose''' the same module A.B.C?  That takes us to Question 2. 
     27The remaining question is this: '''When you say {{{import A.B.C}}}, from what package does A.B.C come?'''.  Three alternatives are under consideration: 
     28  * Plan A (GHC's current story) 
     29  * Plan B: mention the package in the import 
     30  * Plan C: grafting.  See [wiki:PackageMounting Frederik Eaton's proposal] 
     31  
     32---------------------------- 
     33== Plan A: GHC's current story == 
    4034 
    41 == Question 2.  When you say "import A.B.C", from what package does A.B.C come? == 
    42  
    43 Here GHC already has a fairly elaborate scheme (perhaps too elaborate). 
     35GHC already has a fairly elaborate scheme (perhaps too elaborate). 
    4436 * For a start, you may or may not have a package installed.   
    4537 * Even if you do, the package may or may not be exposed by default (reasoning: you may want old versions of package X to be installed, but not in scope by default).   
     
    5042 * What if you want to only replace ''parts'' of P1 (e.g., you want to use an updated version of a module in {{{base}}})? 
    5143 * 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.'' 
    5345 
    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 
     49Another solution is to allow the programmer to specify the source package in the import line, something like this: 
    5550{{{ 
    5651  import A.B.C from "base" ( map, filter )