<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 24, 2016, at 9:33 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Wed, Aug 24, 2016 at 9:25 PM, Matthew Johnson via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><span class=""><blockquote type="cite" class=""><div class="">On Aug 24, 2016, at 9:09 PM, Robert Widmann via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><div style="word-wrap:break-word" class=""><div class="">I have 3 qualms with this proposal as it stands:</div><div class=""><br class=""></div><div class="">- type(of:) will never lie to you.&nbsp;</div><div class=""><br class=""></div><div class="">The only question it won’t answer to your satisfaction is the dynamic type of the NSString you boxed up as an Any.</div><div class=""><br class=""></div><div class="">- No more keywords without significant justification. &nbsp;</div><div class=""><br class=""></div><div class="">I don’t buy the performance use case at all - if you were properly concerned about performance you would try to use as many of Swift’s static features as possible.</div><div class=""><br class=""></div><div class="">- Especially no more keywords that look like they belong in Rust or PHP!</div><div class=""><br class=""></div><div class="">There is no precedent for the spelling of these operations other than the suffixed punctuation. Given that they’re domain-specific, will definitely be hard to use (given that&nbsp;<span style="font-family:Menlo;font-size:11px;color:rgb(112,61,170)" class="">NSString</span><span style="font-family:Menlo;font-size:11px" class="">(string:&nbsp;</span><span style="font-family:Menlo;font-size:11px;color:rgb(209,47,27)" class="">"Bar”</span><span style="font-family:Menlo;font-size:11px" class="">) </span><span style="font-size:11px" class="">may not “really” given you an NSString yet that’s what you asked us to check for “<i class="">really</i>"), and will be obviated by the implementation of SE-0083, I can’t see a reason why we need any of this in the language proper.</span></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">One related topic to consider is exhaustive pattern matching for classes.&nbsp; Now that&nbsp;SE-0117 has been accepted it will be possible to do this for many classes (I would say most if it weren’t for Objective-C classes being so common in Swift and are imported as `open`).&nbsp; Supporting exhaustive pattern matching well would require some kind of syntax for matching the runtime type exactly.&nbsp; I have imagined this as being “exact match” cast operators, which is what the `really_*` operators are.</div></div></div></blockquote><div class=""><br class=""></div><div class="">I don't understand. As pitched, these operators remove bridging magic, but `Subclass really_is Superclass == true`. How would you use this for classes?</div></div></div></div></div></blockquote><div><br class=""></div><div>Bridging is the use case motivating the pitch. &nbsp;I am bringing up a related use case.</div><div><br class=""></div><div>The pitch does not specify&nbsp;`Subclass really_is Superclass == true` and I would argue that this is not the semantics we would want. &nbsp;My interpretation of the proposed solution is:</div><div><br class=""></div><div>"I propose the following operators: really_is, really_as, really_as?, and really_as!. These operators would only return a&nbsp;positive result if the type actually was what was being asked for, instead of something that might be able to bridge to that&nbsp;type <b class="">or a superclass of that type</b>."</div><div><br class=""></div><div>We discussed the exhaustive pattern matching previously in this thread:&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160523/018799.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160523/018799.html</a> where the “exact match” cast operators were called `isExactly` and `asExactly`.</div><div><br class=""></div><div>I think the exhaustive pattern matching use case for classes (and protocols if / when we get sealed protocols) is an important one. &nbsp;I also think doing it right requires the ability to match exact types (i.e. not match subclasses). &nbsp;Maybe there is a better mechanism than a new operators but they would certainly do the job well.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class="">Do you have an alternative in mind for exhaustive pattern matching if we do not introduce exact match cast operators?</div><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class="">~Robert Widmann</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Aug 24, 2016, at 5:08 PM, Charles Srstka via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class="">MOTIVATION:<div class=""><br class=""></div><div class="">SE-0083 appears to be dead in the water, having been deferred until later in Swift 3 back in May and not having been heard from since then, with the Swift 3 release looming closer and closer. However, the predictability gains that would have been provided by this change remain desirable for cases where one needs to know the actual dynamic type of an entity before any bridging magic is involved. Additionally, performance-critical code may desire the ability to check something’s type quickly without incurring the overhead of Objective-C bridging code.</div><div class=""><br class=""></div><div class="">PROPOSED SOLUTION:</div><div class=""><br class=""></div><div class="">I propose the following operators: really_is, really_as, really_as?, and really_as!. These operators would only return a positive result if the type actually was what was being asked for, instead of something that might be able to bridge to that type.</div><div class=""><br class=""></div><div class="">DETAILED DESIGN:</div><div class=""><br class=""></div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">let</span><span class=""> foo: </span><span style="color:#bb2ca2" class="">Any</span><span class=""> = </span><span style="color:#d12f1b" class="">"Foo"</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">let</span><span class=""> bar: </span><span style="color:#bb2ca2" class="">Any</span><span class=""> = </span><span style="color:#703daa" class="">NSString</span><span class="">(string: </span><span style="color:#d12f1b" class="">"Bar"</span><span class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">let</span><span class=""> fooIsString = </span><span style="color:#4f8187" class="">foo</span><span class=""> </span><span style="color:#bb2ca2" class="">is</span><span class=""> </span><span style="color:#703daa" class="">String &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// true</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#703daa" class=""><span style="color:rgb(187,44,162)" class="">let</span><span class="">&nbsp;fooReallyIsString =&nbsp;</span><span style="color:rgb(79,129,135)" class="">foo</span><span class="">&nbsp;</span><span style="color:rgb(187,44,162)" class="">really_is</span><span class="">&nbsp;</span><span class="">String &nbsp; &nbsp; // true</span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#703daa" class=""><br class=""></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">let</span><span class=""> fooIsNSString = </span><span style="color:#4f8187" class="">foo</span><span class=""> </span><span style="color:#bb2ca2" class="">is</span><span class=""> </span><span style="color:#703daa" class="">NSString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// true</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#703daa" class=""><span style="color:rgb(187,44,162)" class="">let</span><span class="">&nbsp;fooReallyIsNSString =&nbsp;</span><span style="color:rgb(79,129,135)" class="">foo</span><span class="">&nbsp;</span><span style="color:rgb(187,44,162)" class="">really_is</span><span class="">&nbsp;</span><span class="">NSString // false</span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">let</span><span class=""> barIsString = </span><span style="color:#4f8187" class="">bar</span><span class=""> </span><span style="color:#bb2ca2" class="">is</span><span class=""> </span><span style="color:#703daa" class="">String &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// true</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#703daa" class=""><span style="color:rgb(187,44,162)" class="">let</span><span class="">&nbsp;barReallyIsString =&nbsp;</span><span style="color:rgb(79,129,135)" class="">bar</span><span class="">&nbsp;</span><span style="color:rgb(187,44,162)" class="">really_is</span><span class="">&nbsp;</span><span class="">String &nbsp; &nbsp; // false</span></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#703daa" class=""><br class=""></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#bb2ca2" class="">let</span><span class=""> barIsNSString = </span><span style="color:#4f8187" class="">bar</span><span class=""> </span><span style="color:#bb2ca2" class="">is</span><span class=""> </span><span style="color:#703daa" class="">NSString &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// true</span></div></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:#703daa" class=""><span style="color:rgb(187,44,162)" class="">let</span><span class="">&nbsp;barReallyIsNSString =&nbsp;</span><span style="color:rgb(79,129,135)" class="">bar</span><span class="">&nbsp;</span></span><span style="color:rgb(187,44,162)" class="">really_is</span><span class="">&nbsp;</span><span style="color:rgb(112,61,170)" class="">NSString // true</span></div><div class=""><span style="color:#703daa" class=""><br class=""></span></div><div class=""><span style="color:#703daa" class=""><span class="">ALTERNATIVES CONSIDERED:</span></span></div><div class=""><span style="color:#703daa" class=""><span class=""><br class=""></span></span></div><div class=""><span class="">Stick with using an unholy combination of Mirror and unsafeBitCast when you need to know what you’ve actually got.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Charles</span></div><div class=""><span class=""><br class=""></span></div></div>______________________________<wbr class="">_________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class=""></div></blockquote></div><br class=""></div></div>______________________________<wbr class="">_________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class=""></div></blockquote></div></div></div><br class=""></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>