Draft GHC Proposal: ScopedImports

Would appreciate any feedback on this new proposal. Thank you in advance.

Discussion

6 Likes

Forgive me if this is explained in the proposal as I have only took a very brief look, but would this be subsumed by the local modules proposal?

4 Likes

If a module A defines an instance, and module B does an scoped import of A for some function, would the instance defined in A be available in the entirety of B?

Yes it is subsumed by LocalModules.

My thoughts on it so far

Yes, this is correct.

Updated the proposal to explicitly state that ScopedImports does not change how instance/module resolution works already and doesn’t affect parts of the grammar like class declarations, instance declarations, pattern synoynms, or any other top-level declarations. Syntactically, ScopedImports only affects where import declarations are allowed. These special import declarations are called scoped import declarations.

Also, updated the proposal based on a commenters idea to force users to explicitly import at least the instances of the module they are using in a scoped import declaration. This simplifies the proposal implementation and aligns with the instance semantics of Haskell.

Hopefully, this clears up some confusion. Still a lot of different interactions to think about and add to the proposal.

Also added a section on how this is different from the LocalModules proposal.