[swift-evolution] Beef up Imports

Developer devteam.codafi at gmail.com
Sat Dec 26 23:12:50 CST 2015

I opened a radar a while ago about improving the import syntax in Swift and haven’t received much of a response, so I’ll try to expand on my thoughts in there here.

I’ve always been in love with the way Agda does Modules and imports.  The syntax is wonderfully natural, and the features it provides are surprisingly useful given their simplicity.  Because Swift forbids the redeclaration of names between structs, enums, classes, and typealiases, I don’t believe that the existing qualified import syntax is needed.  Therefore, I propose the introduction of 3 agda-esque operations for imports to replace the usual `import {func|typealias|struct|class|enum|etc.}` syntax:

	• import Foo using (bar, Baz, qux, corge, …)
	• import Foo hiding (bar, baz, qux, corge, …)
	• import Foo renaming (grault to garply, waldo to fred, …)

The first of these is used to introduce a limited set of identifiers into scope, the second to import all but the given identifiers, and the third to rename identifiers at the module level.  Again, it should be obvious by uniqueness of identifiers what each one is referencing, so qualification of each identifier is unnecessary.  If more context is needed, or more granularity, a Haskell-esque 

import Foo {using|hiding|renaming} (Baz(..) [to Graft(..)])

could be in order for structs, classes, and enums, but I don’t anticipate it will be of much use because individual members are already qualified by their containing structure or instance variable anyway. 

What do you think?

~Robert Widmann

More information about the swift-evolution mailing list