Module re-exportation weekend puzzler

Simon Peyton-Jones simonpj@microsoft.com
Wed, 6 Nov 2002 11:21:39 -0000


Thomas, Iavor,

Thanks for your message.

| Are you saying that you think the report doesn't fully define the
| meaning of the module system, or just that difficult to understand and
| needs to be clarified?

The former, and hence it ought to be clarified.  But after contemplating
your message, your fine formal specification, and then looking at the
Report again, I conclude that my proposed fix was wrong.  (I elaborate
below.) =20

The current wording is this:

|   The form "module M" names the set of all entities whose
|   unqualified name, e, is in scope, and for which the qualified
|   name M.e is also in scope and refers to the same entity as e.

What is un-clear about this is the phrase "...for which the qualified
name M.e is also in scope and refers to e".   Unclear because it could
be read as saying=20
	EITHER: that M.e can refer unambiguously only to this one
entity,=20
	OR: that e is in scope under the name M.e (but M.e could be
ambiguous)

Either would make sense, but the latter is both more symmetrical (see
Cambridge1 vs Cambridge2 below) and matches your formal spec (from which
we should not lightly deviate).

So I am happy to adopt your interpretation, but I'd like to clarify the
wording.
Here's an alternative sentence:
   The form "module M" names the set of all entities that are in
   scope with both an unqualified name 'e' and a qualified name
   'M.e'.

Would that be better?  Can you suggest anything else?

Simo



If anyone else is interested, I'll elaborate Thomas and Iavor's example
slightly:

| module Cambridge1(module Simon) where
|   import PJ as Simon
|   import qualified Marlow as Simon
|=20
| module Cambridge2(module Simon) where
|   import PJ as Simon
|   import Marlow
|
| module Cambridge3(module Simon) where
|   import PJ as Simon
|   import Marlow as Simon
|
| module Marlow where
|   simon =3D "Simon Marlow"
|=20
| module PJ where
|   simon =3D "Simon PJ"

So in Cambridge1
	'simon' is unambiguous
	'Simon.simon' is ambiguous

But in Cambridge2
	'simon' is ambiguous
	'Simon.simon' is unambiguous

In Cambridge 3
	both are ambiguous

The spec as it stands says that the export item 'module M' identifies
those items x that are in scope both as 'x' and as 'M.x'.  In both
Cambridge1 and Cambridge2, there is only one such entity, so both are
legal.   (The fix I proposed yesterday would render Cambridge1 illegal.)


In Cambridge3, the rule would specify that both entities "simon from
module PJ" and "simon from module Marlow" are identified by 'module
Simon'.  And that is illegal because of the last clause of 5.2 specifies
that one cannot export two entities with the same unqualified name.