<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This would be great!<div class=""><br class=""></div><div class="">I use a nearly identical pattern in my networking framework that would be nice to streamline:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">public</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> ==(lhs: </span><span style="font-variant-ligatures: no-common-ligatures" class="">NetworkAddress</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, rhs: </span><span style="font-variant-ligatures: no-common-ligatures" class="">NetworkAddress</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(0, 143, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">// Only addresses of the same protocol are considered equal.</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">guard</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> lhs.</span><span style="font-variant-ligatures: no-common-ligatures" class="">dynamicType</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> == rhs.</span><span style="font-variant-ligatures: no-common-ligatures" class="">dynamicType</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">else</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> lhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">dynamicType</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == IPv4NetworkAddress.</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (lhs </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">as</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">! </span><span style="font-variant-ligatures: no-common-ligatures" class="">IPv4NetworkAddress</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) == (rhs </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">as</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">! </span><span style="font-variant-ligatures: no-common-ligatures" class="">IPv4NetworkAddress</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> lhs.</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">dynamicType</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == IPv6NetworkAddress.</span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (lhs </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">as</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">! </span><span style="font-variant-ligatures: no-common-ligatures" class="">IPv6NetworkAddress</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) == (rhs </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">as</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">! </span><span style="font-variant-ligatures: no-common-ligatures" class="">IPv6NetworkAddress</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures" class="">return</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">false</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">- Will</span></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 13, 2016, at 6:41 PM, Joe Groff 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="">It's been pitched before, but I don't think we'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 class=""><br class="">There'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 "with Self or associated types" and allowing them to be used as dynamic types in addition to static generic constraints. Once you do this, you often want to "open" 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 class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let a: Equatable = /*...*/<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let b: Equatable = /*...*/<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// This is not allowed, since Equatable requires two values with the same static type, but<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// a and b may have different dynamic types.<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>a == b <br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// However, we can dynamically cast one to the other's dynamic type:<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if let bAsA = b as? a.Self {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>return a == bAsA<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let x: RangeReplaceableCollection = /*...*/<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let y: Collection = /*...*/<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// If y has the same dynamic Element type as x, append it to x<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>var z: x.Self = x<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if let yAsX = y as? Any&lt;Collection where Element == x.Element&gt; {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span><span class="Apple-tab-span" style="white-space:pre">        </span>z.append(yAsX)<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class="">`x.Self` then becomes just the first step in this direction.<br class=""><br class="">-Joe<br class="">_______________________________________________<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></div></blockquote></div><br class=""></div></div></body></html>