Modules (again)

Simon Peyton-Jones simonpj@microsoft.com
Thu, 30 Aug 2001 00:56:25 -0700


Folks,

As you gather your wits for ICFP, you may like to consider the following
nice point (thanks to the OGI folk) in the Haskell 98 Report.  Is=20
the following legal? And if so, what is exported?

|           module M(module M) where
|           import A as M

Section 5.2 (Export lists) doesn't anticipate this question; note the
separation between items (5) and (6), whose wording I reproduce below.

Thus provoked, I have come up with another formulation that simplifies
the specification, and evades both this problem and others.  Here it is:

   Replace (5) and (6) by:

   (5')   The form 'module M' abbreviates the set of all entities
	whose unqualified name, 'e', is in scope, and for which=20
	the qualified name 'M.e' is also in scope.  This set may=20
	be empty.

	It is an error to use module M in an export list unless M is=20
	the module bearing the export list, or M is imported by at=20
	least one import declaration (qualified or unqualified).

The second paragraph is unchanged.  The first paragraph encapsulates
rather neatly what we want.  It answers questions like the one I opened=20
with (answer: all local defns and everything imported from A is
exported).

Comments?

Simon

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

The current wording:

(5)   The form `module M' abbreviates the set of all entities whose
names are brought into scope by one or more unqualified import
declarations of the form `import M [impspec]' or `import A as M
[impspec]'. This set may be empty. For example:=20

      module Queue( module Stack, enqueue, dequeue ) where
          import Stack
          ...

Here the module Queue uses the module name Stack in its export list to
abbreviate all the entities imported from Stack.=20

(6) Additionally, a module can name its own local definitions in its
export list using its name in the `module m' syntax. For example:=20

 module Mod1(module Mod1, module Mod2) where
 import Mod2
 import Mod3

Here module Mod1 exports all local definitions as well as those imported
from Mod2 but not those imported from Mod3. Note that module M where is
the same as using module M(module M) where

It is an error to use module M in an export list unless M is the module
bearing the export list, or M is imported by at least one import
declaration (qualified or unqualified).