<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On 27 Dec 2015, at 07:12, Developer via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Therefore, I propose the introduction of 3 agda-esque operations for imports to replace the usual `import {func|typealias|struct|class|enum|etc.}` syntax:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• import Foo using (bar, Baz, qux, corge, …)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• import Foo hiding (bar, baz, qux, corge, …)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>• import Foo renaming (grault to garply, waldo to fred, …)<br class=""></div></div></blockquote><div><br class=""></div><div>+1, but why not just…?</div><div><br class=""></div><div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div><div><div><font color="#00afcd" class=""><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">&nbsp;Foo&nbsp;</span><b style="font-family: Menlo;" class="">using</b></font><span style="font-family: Menlo;" class=""><font color="#00afcd" class="">&nbsp;(bar, Baz, qux,&nbsp;waldo&nbsp;<b class="">as</b>&nbsp;fred)</font>&nbsp;&nbsp;<font color="#919191" class="">// a "whitelist import"</font></span></div></div></div></blockquote><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div><div><div><font color="#00afcd" class=""><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">&nbsp;Foo&nbsp;</span><b style="font-family: Menlo;" class="">hiding</b></font><span style="font-family: Menlo;" class=""><font color="#00afcd" class="">&nbsp;(bar, Baz, qux,&nbsp;waldo&nbsp;<b class="">as</b>&nbsp;fred)</font>&nbsp;<font color="#919191" class="">// a "blacklist import"</font></span></div></div></div></blockquote></div><div><br class=""></div><div>I've been able to work around identifier conflicts with the present <b class=""><font face="Menlo" class="">import</font></b> syntax but it gets clumsy with larger modules. I think both&nbsp;<b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">-</span><b style="font-family: Menlo;" class="">using</b> and&nbsp;<b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">-</span><b style="font-family: Menlo;" class="">hiding</b>&nbsp;would be very welcome in Swift, but the third notation made me double check its semantics from The Agda Wiki.&nbsp;<a href="http://wiki.portal.chalmers.se/agda/pmwiki.php?n=ReferenceManual.Modules#mods" class="">Turns out</a>&nbsp;the&nbsp;<font face="Menlo" class=""><b class="">renaming</b>&nbsp;(...)</font>&nbsp;syntax is actually an extension to the other two and is often used as a part of the one or the other:</div></div><div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">&nbsp;Foo&nbsp;</span><b style="font-family: Menlo;" class="">using</b><span style="font-family: Menlo;" class="">&nbsp;(bar, Baz, qux) <font color="#ff2600" class=""><b class="">renaming</b>&nbsp;(waldo&nbsp;<b class="">to</b> fred)</font></span></div><div><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">&nbsp;Foo&nbsp;</span><b style="font-family: Menlo;" class="">hiding</b><span style="font-family: Menlo;" class="">&nbsp;(bar, Baz, qux)&nbsp;<font color="#ff2600" class=""><b class="">renaming</b>&nbsp;(waldo&nbsp;<b class="">to</b>&nbsp;fred)</font></span></div></div></blockquote><div><div><br class=""></div><div>Why not do without <font face="Menlo" class=""><b class="">renaming</b></font>? Just allow both&nbsp;<b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">-</span><b style="font-family: Menlo;" class="">using</b>&nbsp;and&nbsp;<b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">-</span><b style="font-family: Menlo;" class="">hiding</b>&nbsp;to optionally&nbsp;<i class="">rename</i>&nbsp;imported identifiers. Further, while these keywords can and should be made context-specific, I think it's simplest to reuse "<b class=""><font face="Menlo" class="">as</font></b>" as the associating keyword.</div><div><br class=""></div><div>That would lead us to the&nbsp;<b class="">proposed syntax</b>:</div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div><div><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">&nbsp;Foo&nbsp;</span><b style="font-family: Menlo;" class="">using</b><span style="font-family: Menlo;" class="">&nbsp;(bar, Baz, qux,&nbsp;waldo&nbsp;<b class="">as</b>&nbsp;fred)&nbsp;&nbsp;<font color="#919191" class="">// a "whitelist import"</font></span></div></div></div></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div><div><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class="">&nbsp;Foo&nbsp;</span><b style="font-family: Menlo;" class="">hiding</b><span style="font-family: Menlo;" class="">&nbsp;(bar, Baz, qux,&nbsp;waldo&nbsp;<b class="">as</b>&nbsp;fred) <font color="#919191" class="">// a "blacklist import"</font></span></div></div></div></blockquote><div><div><br class=""></div><div>where the tuple-like parentheses enclose a potentially empty list of identifiers or "identifier&nbsp;<b class=""><font face="Menlo" class="">as</font></b>&nbsp;identifier" mappings. The examples below should clarify the meaning and intended use of these two statements.</div><div><br class=""></div><div><div><blockquote type="cite" class=""><span id="x-apple-selection:end"></span>Again, it should be obvious by uniqueness of identifiers what each one is referencing, so qualification of each identifier is unnecessary.</blockquote></div><div><br class=""></div><div>Agreed. In addition, extending the import statement to class/enum/struct members doesn't make sense to me. Those don't conflict with the global scope at all.</div><div class=""><br class=""></div></div><div>— Pyry Jahkola</div><div><br class=""></div><div><br class=""></div><div>P.S. If this turns into a formal proposal, should we also address how imported operators should be dealt with? Can operators be selectively imported, hidden, or renamed? If renaming is made possible, we should be explicit on how the renamed operator inherits its associativity and precedence from the original one.</div><div><br class=""></div><div><br class=""></div><div><b class=""><font size="5" class="">Examples</font></b></div><div><br class=""></div></div><div class="">Suppose the module <font face="Menlo" class="">Foo</font> contains the following identifiers:<br class=""><br class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="color: rgb(145, 145, 145); font-family: Menlo;" class="">// module Foo:<br class=""></span><span style="color: rgb(145, 145, 145); font-family: Menlo;" class="">// - bar, Baz, qux, waldo</span></blockquote><br class="">The "import-all" remains as it is in Swift 2:<br class=""><font face="Menlo" class=""><b class=""><br class=""></b></font><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class=""> Foo</span><font face="Menlo" class=""><br class=""></font><span style="font-family: Menlo;" class=""><br class=""></span></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo;" class="">_ = (bar, Baz.self, qux, waldo) </span><font color="#919191" style="font-family: Menlo;" class="">// All identifiers can be unqualified.</font></blockquote><font face="Menlo" class=""><br class=""></font>The "import-all" is synonymous with the longer "hide-nothing":<br class=""><font face="Menlo" class=""><b class=""><br class=""></b></font><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class=""> Foo </span><b style="font-family: Menlo;" class="">hiding</b><span style="font-family: Menlo;" class=""> ()</span></blockquote><font face="Menlo" class=""><br class=""></font>To hide or rename an identifier, fill in the parentheses:<br class=""><font face="Menlo" class=""><b class=""><br class=""></b></font><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class=""> Foo </span><b style="font-family: Menlo;" class="">hiding</b><span style="font-family: Menlo;" class=""> (Baz, waldo </span><b style="font-family: Menlo;" class="">as</b><span style="font-family: Menlo;" class=""> fred)</span><font face="Menlo" class=""><br class=""></font><span style="font-family: Menlo;" class=""><br class=""></span></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo;" class="">_ = (bar, qux, fred) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span><font color="#919191" style="font-family: Menlo;" class="">// These names can be unqualified.<br class=""></font><span style="font-family: Menlo;" class="">_ = (Foo.Baz.self, Foo.waldo) &nbsp;&nbsp;</span><font color="#919191" style="font-family: Menlo;" class="">// These names must be qualified.<br class=""></font><span style="font-family: Menlo;" class="">_ = </span><font color="#ff2600" style="font-family: Menlo;" class="">Foo.fred</font><span style="font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><font color="#919191" style="font-family: Menlo;" class="">// Compiler error!</font></blockquote><font face="Menlo" class=""><br class=""></font>To import selectively, potentially renaming identifiers, use the <font face="Menlo" class=""><b class="">import</b>-<b class="">using</b></font>&nbsp;syntax:<br class=""><font face="Menlo" class=""><b class=""><br class=""></b></font><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class=""> Foo </span><b style="font-family: Menlo;" class="">using</b><span style="font-family: Menlo;" class=""> (</span><span style="font-family: Menlo;" class="">Baz&nbsp;</span><b style="font-family: Menlo;" class="">as</b><span style="font-family: Menlo;" class="">&nbsp;FooBaz,&nbsp;</span><span style="font-family: Menlo;" class="">qux, waldo </span><b style="font-family: Menlo;" class="">as</b><span style="font-family: Menlo;" class=""> fred</span><span style="font-family: Menlo;" class="">)</span><font face="Menlo" class=""><br class=""></font><span style="font-family: Menlo;" class=""><br class=""></span></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo;" class="">_ = (FooBaz.self, qux, fred) &nbsp; &nbsp;</span><font color="#919191" style="font-family: Menlo;" class="">// These names can be unqualified.<br class=""></font><span style="font-family: Menlo;" class="">_ = (Foo.Baz.self, Foo.bar) &nbsp; &nbsp; </span><font color="#919191" style="font-family: Menlo;" class="">// These names must be qualified.</font></blockquote><font face="Menlo" class=""><br class=""></font>Finally, it's possible to require qualified use of the Foo module:<br class=""><font face="Menlo" class=""><br class=""></font><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><b style="font-family: Menlo;" class="">import</b><span style="font-family: Menlo;" class=""> Foo </span><b style="font-family: Menlo;" class="">using</b><span style="font-family: Menlo;" class=""> ()</span><font face="Menlo" class=""><br class=""></font><span style="font-family: Menlo;" class=""><br class=""></span></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo;" class="">_ = (Foo.bar, Foo.Baz.self, Foo.qux, Foo.waldo) </span><font color="#919191" style="font-family: Menlo;" class="">// OK.</font><div><div><font face="Menlo" class="">_ = <font color="#ff2600" class="">(bar, Baz.self, qux, waldo)</font>&nbsp;<font color="#919191" class="">// Compiler error x 4!</font></font></div></div></blockquote></div><span id="x-apple-selection:end"></span><div><div><br class=""></div><div>End.</div></div></body></html>