RE: infelicity in module imports
Simon Peyton Jones writes:
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. Relevant quotes from the report, section 5.3.1: "An import declaration that uses the qualified keyword brings into scope only the qualified names of the imported entities (Section 5.5.1); if the qualified keyword is omitted, both qualified and unqualified names are brought into scope" and section 5.5.1: "An import declaration, whether qualified or not, always brings into scope the qualified names of the imported entity." [ aside: should that last word be "entities"? ] I'm taking the term "the imported entities" to mean those entities specified in the import list, or all the exported entities if the import list is omitted. If it doesn't mean this, what's the point of allowing import specifications on a qualified import? If it does mean this, then GHC is correct, but the report's comments about the effect of hiding on qualified names is inconsistent and should be removed (GHC doesn't implement this rule either). Perhaps this is the wrong interpretation, and Simon's is the correct one. But no where that I can find does the report say that an import always brings into scope *all* the qualified names from the imported module regardless of the import list. Cheers, Simon
"Simon Marlow" <simonmar@microsoft.com> writes:
Simon Peyton Jones writes:
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.
Whatever the correct version of this without the `qualified' term, the current GHC behaviour (and I'll confess my reading of the standard up until I spotted this discussion) that allows me to replace import qualified Foo (x, y, z) with import qualified Foo (x, y) import qualified FooFixed as Foo (z) to substitute a different module's z as Foo.z is *very* useful in practice. It seems a pity that import qualified Foo hiding (z) import qualified FooFixed as Foo (z) doesn't also do the natural thing at the moment. (It currently just ignores the `hiding (z)' so Foo.z is ambiguous.) Cheers, Chris.
participants (2)
-
Chris Webb -
Simon Marlow