+1. Completely agree with what Eugene said.<br><div class="gmail_quote"><div dir="ltr">On Thu, Apr 14, 2016 at 1:14 AM Eugene Gubin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I like this idea. I think, if we could use `self` to access instance of self, we should be allowed to use `Self` to access type of self.</div><div class="gmail_extra"><br><div class="gmail_quote">2016-04-14 8:46 GMT+04:00 William Dillon via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">This would be great!<div><br></div><div>I use a nearly identical pattern in my networking framework that would be nice to streamline:<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;color:rgb(52,149,175)"><span style="color:#0433ff">public</span><span style="color:#000000"> </span><span style="color:#0433ff">func</span><span style="color:#000000"> ==(lhs: </span><span>NetworkAddress</span><span style="color:#000000">, rhs: </span><span>NetworkAddress</span><span style="color:#000000">) -&gt; </span><span>Bool</span><span style="color:#000000"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;color:rgb(0,143,0)"><span style="color:#000000">    </span><span>// Only addresses of the same protocol are considered equal.</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;color:rgb(4,51,255)"><span style="color:#000000">    </span><span>guard</span><span style="color:#000000"> lhs.</span><span>dynamicType</span><span style="color:#000000"> == rhs.</span><span>dynamicType</span><span style="color:#000000"> </span><span>else</span><span style="color:#000000"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;color:rgb(4,51,255)"><span style="color:#000000">        </span><span>return</span><span style="color:#000000"> </span><span>false</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span>    }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span>    </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span>    </span><span style="color:#0433ff">if</span><span> lhs.</span><span style="color:#0433ff">dynamicType</span><span> == IPv4NetworkAddress.</span><span style="color:#0433ff">self</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;color:rgb(52,149,175)"><span style="color:#000000">        </span><span style="color:#0433ff">return</span><span style="color:#000000"> (lhs </span><span style="color:#0433ff">as</span><span style="color:#000000">! </span><span>IPv4NetworkAddress</span><span style="color:#000000">) == (rhs </span><span style="color:#0433ff">as</span><span style="color:#000000">! </span><span>IPv4NetworkAddress</span><span style="color:#000000">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span>    }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span>    </span><span style="color:#0433ff">if</span><span> lhs.</span><span style="color:#0433ff">dynamicType</span><span> == IPv6NetworkAddress.</span><span style="color:#0433ff">self</span><span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;color:rgb(52,149,175)"><span style="color:#000000">        </span><span style="color:#0433ff">return</span><span style="color:#000000"> (lhs </span><span style="color:#0433ff">as</span><span style="color:#000000">! </span><span>IPv6NetworkAddress</span><span style="color:#000000">) == (rhs </span><span style="color:#0433ff">as</span><span style="color:#000000">! </span><span>IPv6NetworkAddress</span><span style="color:#000000">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span>    }</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;min-height:13px"><span>    </span><br></p><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;;color:rgb(4,51,255)"><span style="color:#000000">    </span><span>return</span><span style="color:#000000"> </span><span>false</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span>}</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:&#39;Fira Code&#39;"><span>- Will</span></div><div><div><div><br><div><blockquote type="cite"><div>On Apr 13, 2016, at 6:41 PM, Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div>It&#39;s been pitched before, but I don&#39;t think we&#39;ve had a dedicated thread to this idea. Erica has proposed making `Self` generally available within methods in types to refer to the dynamic type of the current receiver. One could think of `Self` as a special associated type member that exists in every type for this purpose. This also happens to be what you get when ask for the `dynamicType` member of a value. We could unify these concepts and get rid of the clunky `dynamicType` keyword, replacing it with `x.Self`.<br><br>There&#39;s another benefit to this syntax change. Looking to the future, one of the many features Doug pitched in his generics manifesto was to generalize protocol existentials, lifting our current restrictions on protocols &quot;with Self or associated types&quot; and allowing them to be used as dynamic types in addition to static generic constraints. Once you do this, you often want to &quot;open&quot; the type of the existential, so that you can refer to its Self and associated types in the types of other values. I think a natural way would be to let you directly use Self and associated type members of existentials as types themselves, for example:<br><br><span style="white-space:pre-wrap">        </span>let a: Equatable = /*...*/<br><span style="white-space:pre-wrap">        </span>let b: Equatable = /*...*/<br><br><span style="white-space:pre-wrap">        </span>// This is not allowed, since Equatable requires two values with the same static type, but<br><span style="white-space:pre-wrap">        </span>// a and b may have different dynamic types.<br><span style="white-space:pre-wrap">        </span>a == b <br><br><span style="white-space:pre-wrap">        </span>// However, we can dynamically cast one to the other&#39;s dynamic type:<br><span style="white-space:pre-wrap">        </span>if let bAsA = b as? a.Self {<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>return a == bAsA<br><span style="white-space:pre-wrap">        </span>}<br><br><span style="white-space:pre-wrap">        </span>let x: RangeReplaceableCollection = /*...*/<br><span style="white-space:pre-wrap">        </span>let y: Collection = /*...*/<br><br><span style="white-space:pre-wrap">        </span>// If y has the same dynamic Element type as x, append it to x<br><span style="white-space:pre-wrap">        </span>var z: x.Self = x<br><span style="white-space:pre-wrap">        </span>if let yAsX = y as? Any&lt;Collection where Element == x.Element&gt; {<br><span style="white-space:pre-wrap">        </span><span style="white-space:pre-wrap">        </span>z.append(yAsX)<br><span style="white-space:pre-wrap">        </span>}<br><br>`x.Self` then becomes just the first step in this direction.<br><br>-Joe<br>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></div></blockquote></div><br></div></div></div></div></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>