| | > Currently, you are permitted to write | | > | | > import A hiding (f) | | > import B as A (f) | | > | | > and this means that everything exported from module A is visible, | | > with the exception that function `f' is overridden by a different | | > definition from module B. Here, a reference to `A.f' is resolved | | > unambiguously to `B.f'. | | | | In my understanding of the report, this is not true. Quoting from | | section 5.3 of the report | | | | "The hiding clause only applies to unqualified names. In the previous | | example, the name M.C is brought into scope." | | | | Thus, in your example, the declaration import A hiding (f) will bring | | A.f into scope and thus A.f is ambiguous! Wolfgang is correct. I don't see how the report can be read any other way. | However, if you are indeed correct, then we have an even stranger | situation: | | import A (g) | | brings only A.g into scope, but | | import A hiding (f) | | brings both A.f and A.g into scope! So `hiding' is doing the | opposite of hiding, and in fact _reveals_ names. No, that's not so. Let's assume that A exports f,g,h. The report says (first sentence of 5.3.1) "if the qualified keyword is omitted, both qualified and unqualified names are brought into scope". So both the above imports bring into scope A.f and A.g and A.h; the former also brings unqualified 'g' into scope, while the latter also brings 'g' and 'h' into scope. 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. As to whether this is a good design, I'm sure one could suggest others, but I'm very strongly biased against fixing anything that is not a Bug. As to whether it is clearly stated, presumably the answer is 'no', since Malcolm (an expert by any lights) has misunderstood it in two different ways. That I would like to fix. Can anyone suggest a way to make the report clearer? Simon
In short, an import *always* brings the entire *qualified* set of names into scope. Hiding and revealing applies only to unqualified names.
I agree with SimonM that this is not what the Report says. At one time it may have done, but careful reading shows that only the qualified names for _explicitly_named_ impspecs are brought into scope.
I must say that I thought GHC implemented this rule; if not I should fix it.
As SimonM points out, if that is the rule then _all_ impspecs (both explicit namings and hidings) on an `import qualified' are ignored, so we should delete them from the grammar.
As to whether this is a good design, I'm sure one could suggest others, but I'm very strongly biased against fixing anything that is not a Bug.
No matter which of the interpretations of the current Report (so far mentioned on the list) we choose, they all have design inconsistencies. So I think we need to correct the design. SimonM's suggested fix leads to the most intuitive interpretation I think. Regards, Malcolm
participants (2)
-
Malcolm Wallace -
Simon Peyton-Jones