<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="">I'm not quite sure I understand the 'Additional Utility' section. A given class hierarchy can only have one implementation of a given static method; static methods are effectively final. Therefore, the 'Self' introduced in the previous proposal should be completely sufficient for invoking a static method on a class. (Likewise, for moving around code.) In fact, the previous proposal for 'Self' used a very similar example.<div class=""><br class=""></div><div class="">I think the example would make more sense if it involved class methods. However, *without considering the protocol applications* I wouldn't consider that a compelling enough use case, by itself, to add StaticSelf.</div><div class=""><br class=""></div><div class="">As for StaticSelf's impact on protocols, I defer to the opinions of the other folks who've commented on the thread.</div><div class=""><br class=""></div><div class="">Austin</div><div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 12, 2016, at 5:49 PM, Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Erica Sadun and I have written a proposal are following up the recent discussion thread "[RFC] #Self” with a proposal to introduce StaticSelf, an invariant Self.<div class=""><div class=""><br class=""></div><div class="">The recent discussion can be found here: <a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/16565" class="">http://thread.gmane.org/gmane.comp.lang.swift.evolution/16565</a></div><div class=""><br class=""></div><div class="">The proposal can be found here: <a href="https://github.com/anandabits/swift-evolution/blob/static-self/proposals/NNNN-static-self.md" class="">https://github.com/anandabits/swift-evolution/blob/static-self/proposals/NNNN-static-self.md</a></div><div class=""><br class=""></div><div class="">We look forward to continuing the discussion. We plan to submit a PR in the near future after incorporating your final feedback.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Matthew</div><div class=""><h1 id="introducingstaticselfaninvariantself" style="font-size: 37px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Introducing StaticSelf, an Invariant Self</h1><ul style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;" class=""><li style="font-size: 17px;" class="">Proposal: TBD</li><li style="font-size: 17px;" class="">Authors: <a href="https://github.com/anandabits" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">Matthew Johnson</a>, <a href="https://github.com/erica" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">Erica Sadun</a></li><li style="font-size: 17px;" class="">Status: TBD</li><li style="font-size: 17px;" class="">Review manager: TBD</li></ul><h2 id="introduction" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Introduction</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">This proposal introduces a new keyword that provides consistent invariant type semantics in all contexts.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class=""><em style="line-height: 1;" class="">The Swift-evolution thread about this topic can be found here: <a href="http://thread.gmane.org/gmane.comp.lang.swift.evolution/16565" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">[RFC] #Self</a></em></p><h2 id="motivation" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Motivation</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The distinction between covariant and non-covariant type references come into play when<br class="">conforming non-final classes to protocols. Fixing a protocol requirement to a covarying type<br class="">means that a method returning <code style="line-height: 1;" class="">Self</code> must be overriden by all subclasses in order to return<br class="">the correct, matching type.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">This proposal builds on the covariant construct <code style="line-height: 1;" class="">Self</code> accepted in <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">SE–0068</a><br class="">to introduce an invariant type identifier. It enables protocol declarations to consistently<br class="">refer to a type that is fixed at compile time. This ensures that subclasses can inherit<br class="">protocol implementations without having to re-implement that code at each level of<br class="">inheritance.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">Under this proposal, a new identifier keyword is fixed in use <em style="line-height: 1;" class="">at the point of protocol conformance</em><br class="">to the static type of that construct. </p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; height: 36px; background-color: rgb(248, 248, 248);" class=""><code class="(null) kotlin hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">class</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">A</span>: <span class="hljs-typename">MyProtocol</span></span></code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The invariant <code style="line-height: 1;" class="">StaticSelf</code> identifier will always refer to <code style="line-height: 1;" class="">A</code>, unlike <code style="line-height: 1;" class="">Self</code>, which is covarying and refers to<br class="">the type of the actual instance. Since multiple inheritance for non-protocol types is disallowed,<br class="">this establishes this invariant type identifier with no possibility for conflict.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">Consider the following example, under the current system:</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; height: 204px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">StringCreatable</span> </span>{
<span class="hljs-keyword" style="font-weight: bold;">static</span> <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">createWithString</span><span class="hljs-params">(s: String)</span></span> -> <span class="hljs-type">Self</span>
}
<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">NSURL</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">StringCreatable</span> </span>{
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// cannot conform because NSURL is non-final</span>
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// error: method 'createWithString' in non-final class 'NSURL' must return `Self` to conform to protocol 'A'</span>
}</code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">Introducing a static, invariant version of <code style="line-height: 1;" class="">Self</code> permits the desired conformance:</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; height: 288px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">protocol</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">StringCreatable</span> </span>{
<span class="hljs-keyword" style="font-weight: bold;">static</span> <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">createWithString</span><span class="hljs-params">(s: String)</span></span> -> <span class="hljs-type">StaticSelf</span>
}
<span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">extension</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">NSURL</span>: <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">StringCreatable</span> </span>{
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// can now conform conform because NSURL is fixed and matches the static</span>
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// type of the conforming construct. Subclasses need not re-implement</span>
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// <span class="hljs-doctag">NOTE:</span> the return type can be declared as StaticSelf *or* as NSURL</span>
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// they are interchangeable</span>
<span class="hljs-keyword" style="font-weight: bold;">static</span> <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">createWithString</span><span class="hljs-params">(s: String)</span></span> -> <span class="hljs-type">StaticSelf</span> {
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// ...</span>
}
}</code></pre><h3 id="additionalutility" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Additional Utility</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The utility of <code style="line-height: 1;" class="">StaticSelf</code> is not limited to protocols. A secondary use enables code to refer to the lexical context’s current type without explicitly mentioning its name. This provides a useful shortcut when referencing static type members with especially long names and when re-purposing code between types.</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; height: 225px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-class"><span class="hljs-keyword" style="font-weight: bold;">class</span> <span class="hljs-title" style="color: rgb(68, 85, 136); font-weight: bold;">StructWithAVeryLongName</span> </span>{
<span class="hljs-keyword" style="font-weight: bold;">static</span> <span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">()</span></span> -> <span class="hljs-type">String</span> {
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// ...</span>
}
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">()</span></span> {
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// ...</span>
<span class="hljs-keyword" style="font-weight: bold;">let</span> s = <span class="hljs-type">StaticSelf</span>.foo()
<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">//</span>
}
}</code></pre><h2 id="detaileddesign" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Detailed Design</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">This proposal introduces <code style="line-height: 1;" class="">StaticSelf</code>, a new keyword that may be used in protocols to refer to the invariant static type of a conforming construct. <code style="line-height: 1;" class="">StaticSelf</code> may also be used in the lexical context of any type declaration. In such use, the keyword is identical to spelling out the full name of that type.</p><h2 id="impactonexistingcode" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Impact on existing code</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">Being additive, there should be no impact on existing code.</p><h2 id="alternativesconsidered" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Alternatives considered</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The keyword is not fixed at this time. Alternatives that have been discussed include <code style="line-height: 1;" class="">StaticType</code>, <code style="line-height: 1;" class="">InvariantSelf</code>, <code style="line-height: 1;" class="">SelfType</code>, or <code style="line-height: 1;" class="">Type</code>. The community is welcome to bikeshed on the most clear and concise name for this keyword.</p></div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>