GHC should inform where unknown identifiers originate whenever possible
Assume I have a module Foo, using implicit imports and unqualified identifiers (minimalistic example, actual cases could have hundreds of imported modules).
module Foo
import Data.List
foo = intersperse ...
If I decide to switch to explicit imports, I have two options. I could import Data.List as qualified, or add an explicit export list. In both cases the origin of 'intersperse' will be unambiguous. If I choose qualified imports, GHC will helpfully tell me where all now unqualified identifiers originated.
Not in scope: type constructor or class ‘intersperse’
Perhaps you meant one of these:
‘Data.List.intersperse’
However, If I chose to add an explicit import list to the 'Data.List' import, I will have no such help. Again, if the number of imported modules is long, there is no obvious way to tell which module should have the explicit import by just looking at the code. On the other hand, as the above case shows GHC is obviously able to infer this. I can accomplish it by manually duplicating my import list, and adding a qualified import of every imported module, but this is a lot of manual work in modules with many imports.
I suggest that for the purposes of error messages, top-level identifiers not in scope should be searched for in every module as if it had been imported qualified, and an error message akin to the following should be generated. Obviously, if the identifier is availble from a a qualified import, the above error message should take precedence.
Not in scope: type constructor or class ‘intersperse’.
It is available but not imported from the following modules:
‘Data.List.intersperse’
To bring the identifier into scope, import it from the one of the above modules, or use a qualified import.
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.2 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |