infelicity in module imports

Brian Boutel
Thu, 12 Jul 2001 13:46:23 +1200

Option 2 is closer to what the syntax of imports, read as English, suggests
is intended, but, if it wasn't for that, I'd be promoting option 1.
The primary purpose of being able to restrict imports is to avoid name
clashes, and with qualified import there is no risk of a clash, so no need
for restrictions.

Even with option 2, there is scope for confusion. "Import" without
"qualified", imports both qualified and unqualified names, but adding the
word "qualified" doesn't make any difference to the position of qualified
names, but instead silently fails to import unqualified names.
There is still a strange asymmetry, too. Whereas adding "qualified" to
"import Modname ( a, b, c)" doesn't change which entities are imported, just
the ability to refer to them by unqualified names, adding qualified" to
"import Modname hiding ( a, b, c)" has the effect of importing everything
that was previously hidden.

Personally, I think the right solution is to import entire modules (the
exported parts) qualified, and optionally to allow unqualified reference to
some or all names, with a syntax like
    import modid [as modid] [unqualifying ( [all except] impspec] | all)

but it's probably too late for this.


Simon Peyton-Jones wrote:

> Folks
> It seems that I forgot to send this message a couple of weeks ago.
> Assuming that silence meant assent, I implemented the proposal below
> in the report I put out yesterday.  But in this case silence meant you
> hadn't
> been asked (an excellent way to reach consensus that I must remember
> for the future).
> So here's the message anyway.  I don't think it's controversial, since
> it's
> the outcome the cognoscenti were seeking, and no one else will care.
> Well, so I hope!
> Simon
> | > In short, an import *always* brings the entire *qualified*
> | > set of names into scope. Hiding and revealing applies only
> | > to unqualified names.  I must say that I thought GHC implemented
> | > this rule; if not I should fix it.
> |
> | That's not my reading of the report, and it's not what GHC implements.
> |
> |       import A (f)
> |
> | brings only f and A.f into scope.
> How embarassing.  Now I look at it (yet) again, the report is certainly
> ambiguous about whether
>         import A(f)
> imports A.g as well.  But SimonM is right to say that the implication
> is that it does *not*  (contrary to my earlier message).  But if it does
> not,
> then the treatment of hiding and explicit-listing is inconsistent, which
> is
> a Bug.
> There are two consistent positions
> 1. Every import of module A (no matter how constrained) imports
> all of A's exports with qualified names.  Import of qualified names is
> unaffected by both hiding clauses and the explicit entity list
> 2. The explicit entity list, or hiding clause, for an import determines
> which
> entities are imported.  The qualified names of all these entities are
> brought
> into scope; in addition, for an unqualified import the unqualified names
> are
> brought into scope too.
> Everyone who has spoken favours (2), and indeed GHC implements it.
> So I propose to change the report to say that much more explicitly.
> Any objections?
> Simon
> _______________________________________________
> Haskell mailing list