[swift-evolution] Beef up Imports

Chris Lattner clattner at apple.com
Mon Dec 28 18:07:18 CST 2015


> On Dec 26, 2015, at 9:12 PM, Developer via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 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 

+1 for this general direction, if not this specific syntax.  It would also be great to have import integrate with SPM so you can import a package from an SCM URL.  This would be pretty handy in particular for #! scripts.

-Chris


More information about the swift-evolution mailing list