[swift-evolution] Beef up Imports

Pyry Jahkola pyry.jahkola at iki.fi
Thu Jan 7 07:52:05 CST 2016

> On 07 Jan 2016, at 11:59, Developer via swift-evolution <swift-evolution at swift.org> wrote:
> I'll admit, Agda does seem to use 'renaming' to enable notational preference first and foremost.  I'm not sure of too many Swift authors who would put something like that too high on their list of concerns, so +1.  Drop renaming.

I tend to also agree. One more reason not to rename imported identifiers is that it makes them less googleable at call site; there's an extra human indirection (looking up the respective import statement) before being successfully at searching with the commonly known name.

But is there more we could prune away from this proposal? When would you really want to hide or selectively choose any qualified imports? If qualified imports always imported all identifiers, with the restriction that they must be qualified, would there (should there) ever be conflicts with anything else imported or locally defined?

It seems to me we could simplify it all down to just:

import Lib              // Works just like in Swift 2, qualified or not.
import Lib (Foo, bar)   // Only Foo and bar unqualified, others like Lib.qux.
import Lib ()           // Everything must be qualified: Lib.Foo etc.
import Lib hiding (qux) // Everything but baz works unqualified, and all like Lib.qux.
import Lib as L         // Import all unqualified, allow qualification under L like L.Foo.
import Lib as L (Foo)   // Only Foo unqualified, others under L like L.bar.
import Lib as L ()      // Everything must be qualified under L like L.Foo etc.
import Lib as L hiding (qux) // ..., qux must be qualified like L.qux.

Wouldn't that work pretty nicely, with minimal additions to syntax?

— Pyry

P.S. Okay, I can come up with a somewhat contrived corner case: What to do with modules whose names collide with type names imported unqualified, e.g. https://github.com/robrix/Either <https://github.com/robrix/Either> ?

import Lib // defines bar like above (1)

struct Lib {
    static func bar() {} // (2)

Lib.bar() // Which one gets called, (1) or (2)?

One might suggest the above call resolved to the locally defined function. How about if struct Lib was defined in another module that was also imported?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160107/7ec255f8/attachment.html>

More information about the swift-evolution mailing list