<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 don’t have a problem with Optionals being comparable, but I do see the potential for bugs occurring as Swift automatically wraps values as Optionals when required. Not sure what the solution would be here, other than to make the wrapping of values explicit?<div class=""><br class=""></div><div class="">Here’s an example of when automatic Optional wrapping can cause unexpected results:</div><div class=""><br class=""></div><div class=""><div class="">struct Pet {</div><div class="">&nbsp; let age: Int</div><div class="">}</div><div class=""><br class=""></div><div class="">struct Person {</div><div class="">&nbsp; let name: String</div><div class="">&nbsp; let pet: Pet?</div><div class="">}</div><div class=""><br class=""></div><div class="">let peeps = [</div><div class="">&nbsp; Person(name: "Fred", pet: Pet(age: 5)),</div><div class="">&nbsp; Person(name: "Jill", pet: .None), // no pet here</div><div class="">&nbsp; Person(name: "Burt", pet: Pet(age: 10)),</div><div class="">]</div><div class=""><br class=""></div><div class="">let ps = peeps.filter { $0.pet?.age &lt; 6 }</div><div class=""><br class=""></div><div class="">ps == [Fred, Jill] // if you don’t own a pet, your non-existent pet is considered to be younger than any actual pet &nbsp;🐶</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">If the Optional wrapping of ‘6’ in the comparison had to be explicit, then the result wouldn't be so unexpected.</div><div class=""><br class=""></div><div class="">Al</div><div class=""><br class=""></div><div class=""><br class=""></div></div><div><blockquote type="cite" class=""><div class="">On 9 Dec 2015, at 11:31, Lucas Derraugh &lt;<a href="mailto:lucas.derraugh@me.com" class="">lucas.derraugh@me.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">This is related to a question I asked on SO a while back:&nbsp;<a href="http://stackoverflow.com/questions/26172911/swift-nil-has-a-numeric-value" class="">http://stackoverflow.com/questions/26172911/swift-nil-has-a-numeric-value</a></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class=""><br class=""></div><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px;" class="">Seems that many others have had confusion with the same problem, and it can sneak into your code without being aware of it. The simple case that I ran into was comparing an Optional Int to an Int. It is a very subtle bug and one that I don’t think should be allowed to occur. To me the intent isn't clear in this situation. I don’t think nil should be considered true or false if compared against. The only alternative I can think of is if comparing anything to a nil value, the result would be false; this would probably still lead to unexpected behavior though.</div><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div id="bloop_sign_1449659971674371072" class="bloop_sign" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: helvetica, arial; font-size: 13px;" class="">Lucas Derraugh<br class=""><a href="mailto:lucas.derraugh@me.com" class="">lucas.derraugh@me.com</a></div><div style="font-family: helvetica, arial; font-size: 13px;" class="">607-793-3517<span class="Apple-tab-span" style="white-space: pre;">        </span></div></div><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><p class="airmail_on" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On December 9, 2015 at 6:10:40 AM, Al Skipp via swift-evolution (<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>) wrote:</p><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class=""><div class=""></div><blockquote type="cite" class=""><pre class="" style="white-space: pre-wrap; background-color: rgb(255, 255, 255);">To me it seems logical that comparing Optional&lt;Int&gt; with Int (or another
Optional&lt;Int&gt;), if it's allowed at all, should return Optional&lt;Bool&gt;. Since
conditional statements only accept Bool, the user is forced to handle the
nil case explicitly.
</pre></blockquote><div class="">I disagree that comparing Optional values should have a return value of Optional&lt;Bool&gt;.</div><div class="">If the following were to be true:</div><div class=""><br class=""></div><div class="">.None &lt; .Some(0) == .None</div><div class=""><br class=""></div><div class="">Then logically, this would be too:</div><div class=""><br class=""></div><div class="">[] &lt; [1,2,3] == []</div><div class=""><br class=""></div><div class="">I think most people would agree that the correct result to that comparison should be ‘true’, not [].</div><div class=""><br class=""></div><div class="">When comparing ‘container’ types I think it’s important to have a simple Bool result, otherwise things get very peculiar (conceptually the Optional type is really just a container with a maximum count of 1).</div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=jmhDxcaxa3uq2rlI6BgFHRrxrj-2Bs36SiRq7BRdjtWBvMfe1Bm7ILNxUSz6dnTlNGKB0U9un-2BJw43J8Eug-2B6e94KXSHEs43BltcCxCL6xHZ6Vz1je-2BF71w2PPuurExpuEpjqFTe40gYXr7THh6c-2BHg4bIcUB-2BLxd9Pi-2F2ACvc8lOR4hLv1rzUc-2FiNHhsHSn9RC2rrnH-2F5fsg2Df-2FFV-2BPEdyLAhCTgeivUcNNBL-2F6RjDE-3D" alt="" width="1" height="1" border="0" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class="">&nbsp;_______________________________________________<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" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></blockquote></div></blockquote></div><br class=""></body></html>