<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 Jul 11, 2016, at 6:02 PM, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote">On Mon, Jul 11, 2016 at 5:58 PM, Chris Lattner <span dir="ltr" class=""><<a href="mailto:clattner@apple.com" target="_blank" class="">clattner@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Jul 11, 2016, at 4:56 PM, Jacob Bandes-Storch via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class="">
> Personally I think we should just remove these optional-taking variants of the comparison operators. Does anyone agree/disagree?<br class="">
><br class="">
> It does make sense to keep ==(T?, T?) and !=(T?, T?), and if coercion were removed, we might want to add (T, T?) and (T?, T) versions. Are there any other operators that would be affected by your proposal? If not, removing the optional </<=/>/>= would obviate the need to remove coercion.<br class="">
<br class="">
</span>My opinion:<br class="">
- We need to remove T -> T? promotion from operators for a whole lot of reasons. People are frequently surprised by the behavior of the ?? operator promoting the LHS to optional, for example. There are a ton of “bugs” that people file that are related to issues like that.<br class=""></blockquote><div class=""><br class=""></div><div class="">Thinking about this a bit more, couldn't the same class of "gotcha" happen with regular functions, too? Why should this be changed for operators specifically?</div></div></div></div></div></blockquote><div><br class=""></div>This occurred to me when I was considering this over the weekend, but operators are already quite special. You can specify whether they are infix, prefix, or postfix, and assign a precedence. They are used without any special syntax to “apply” them, unlike normal functions which are applied with (…). I would go as far as saying that most (non-PL, non-compiler implementor) people wouldn’t consider operators and normal functions to be very closely related at all.</div><div><br class=""></div><div>We clearly wouldn’t want to remove the coercion for the regular functions because it’s extremely convenient. I know you’re not suggesting doing so, I’m just pointing out that if we made things uniform we’d clearly have to keep the coercion by default.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">Maybe it makes more sense to have some kind of "@noncoercing" parameter, so that coercion can still take place, but operator could be defined as `func ??<T>(lhs: @noncoercing T?, rhs: T?)`</div></div></div></div></div></blockquote><div><br class=""></div>I’m not sure it’s really worth adding another attribute just for this purpose.</div><div><br class=""></div><div>Mark</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- We don’t have conditional conformances, so Optional cannot conditionally conform to Equatable and Comparable in Swift 3. In a later release, we can consider whether adding them is a good idea.<br class="">
- We currently support equatable comparing an arbitrary optional to nil (one in which T is not necessarily Equatable), which I think is useful to keep around.<br class="">
- If we allow that, then it makes sense to allow == and != operators for optionals where T is Equatable, even though the optional itself cannot conditionally conform to Equatable. The “surprising” aspect of equatable comparison doing promotions will have been removed.<br class="">
<br class="">
The questionable piece is what to do with </<=/>/>=. I would lean towards removing them in Swift 3 simply because it is easier to "remove now, but add them back later" if they really are important. The argument for keeping them is that the surprising aspect will be solved by removing the first promotion - "42 > nil” will cease to type-check, so they may not actually be harmful anymore.<br class="">
<span class="HOEnZb"><font color="#888888" class=""><br class="">
-Chris</font></span></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>