<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 07 Mar 2016, at 23:29, Sébastien Blondiau via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I think there should be two distinct operators:</div><div class=""><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><div style="font-family: Helvetica; font-size: 12px;" class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">var</span><span style="" class=""> certainlyOptional = </span><font color="#4f8187" class="">value</font><span style="" class=""> </span><span style="" class="">?? </span><font color="#4f8187" class="">otherValue</font></div><div style="" class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="color: rgb(187, 44, 162);" class="">var</span><span style="" class=""> </span><span style="" class="">certainlyNotOptional</span><span style="" class=""> = </span><font color="#4f8187" class="">value</font><span style="" class=""> ?! </span><font color="#4f8187" class="">notOptionalValue</font></div></div></div></div></div></div></div></div></blockquote></div><br class=""><div class="">Consider a parallel Swiftverse where the standard library only defined the following single overload of `<span style="font-family: Menlo;" class="">??</span>`:<div class=""><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">infix<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>operator<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> ?? { </span>associativity<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> right </span>precedence<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">131</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> }</span></div></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> ?? <T>(x: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>?, <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@autoclosure</span> y: () -> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span> {</div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> x = x { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> x } <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">else</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> y() }</div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class="">}</div></div></blockquote><div class=""><br class=""></div><div class="">With that defined, life went on and things worked just fine:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">let</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo;" class="">some:</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(112, 61, 170);" class="">Int</span><span style="font-family: Menlo;" class="">? =</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(39, 42, 216);" class="">1</span><br class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(187, 44, 162);" class="">let</span> none: <span style="color: rgb(112, 61, 170);" class="">Int</span>? = <span style="color: rgb(187, 44, 162);" class="">nil</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> one = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">some</span> <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">??</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span> <span style="color: rgb(0, 132, 0);" class="">// = <b class="">1</b>: Int</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> two = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">none</span> <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">??</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span> <span style="color: rgb(0, 132, 0);" class="">// = <b class="">2</b>: Int</span></div></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> ein = <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">none</span> <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">??</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">some</span> <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">??</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">3</span> <span style="font-variant-ligatures: no-common-ligatures; color: #008400" class="">// = <b class="">1</b>: Int</span></div></div></blockquote><div class=""><br class=""></div><div class="">(That last line, by the way, is equivalent to `<span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">none</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> (</span><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">some</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(39, 42, 216);" class="">3</span><span style="font-family: Menlo;" class="">)</span>` because of the right associativity.)</div><div class=""><br class=""></div><div class="">However, because of implicit optional wrapping, the following lines compiled as well:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">let</span><span style="font-family: Menlo;" class=""> un =</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">some</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(0, 132, 0); font-family: Menlo;" class="">// = <b class="">Optional(1)</b>: Int?</span></blockquote><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">let</span><span style="font-family: Menlo;" class=""> deux =</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(39, 42, 216);" class="">2</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(0, 132, 0); font-family: Menlo;" class="">// = <b class="">Optional(2)</b>: Int?</span></div></blockquote><div class=""><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">let</span><span style="font-family: Menlo;" class=""> rien =</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">some</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(0, 132, 0); font-family: Menlo;" class="">// = <b class="">nil</b>: Int?</span></blockquote></div><div class=""><span style="color: rgb(0, 132, 0); font-family: Menlo;" class=""><br class=""></span></div><div class="">The reason was the compiler would <font face="Menlo" class="">Optional</font>-wrap the left-hand side of `<font face="Menlo" class="">??</font>` over and over again, until the argument pair met the shape `<font face="Menlo" class="">(T?, T)</font>` for a type `<font face="Menlo" class="">T</font>`, which happened to be `<font face="Menlo" class="">Int?</font>` in this case:</div><div class=""><br class=""></div><div class=""><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">some</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none </span><span style="font-family: Menlo;" class="">→ Optional(</span><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">some</span><span style="font-family: Menlo;" class="">) </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span></blockquote><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo; color: rgb(39, 42, 216);" class="">2</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span><span style="font-family: Menlo;" class=""> → </span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo;" class="">Optional(</span><span style="font-family: Menlo;" class="">Optional(</span><span style="font-family: Menlo; color: rgb(39, 42, 216);" class="">2))</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span></blockquote><div class=""><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">some</span><span style="font-family: Menlo;" class=""> → </span><span style="font-family: Menlo;" class="">Optional(</span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span><span style="font-family: Menlo;" class="">) </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">some</span></blockquote></div></div><div class=""><br class=""></div><div class="">Don't you think the last line was especially surprising? Just a couple of lines up, the definition of `<font face="Menlo" class="">ein</font>` looked almost identical:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">let</span><span style="font-family: Menlo;" class=""> ein = </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">some</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(39, 42, 216);" class="">3</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(0, 132, 0);" class="">// = <b class="">1</b>: Int</span></div><div class=""><span style="font-family: Menlo; color: rgb(187, 44, 162);" class="">let</span><span style="font-family: Menlo;" class=""> rien =</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(79, 129, 135);" class="">none</span><span style="font-family: Menlo;" class=""> </span><span style="font-family: Menlo; color: rgb(49, 89, 93);" class="">??</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(79, 129, 135); font-family: Menlo;" class="">some</span><span style="font-family: Menlo;" class=""> </span><span style="color: rgb(0, 132, 0); font-family: Menlo;" class="">// = <b class="">nil</b>: Int?</span></div></blockquote><div class=""><br class=""></div><div class="">…yet with an entirely different result! Of course that's just because of associativity rules, but who remembered! So I guess in our world, the intention with the second overload `<font face="Menlo" class="">(T?, T?) -> T?</font>` is beginner friendliness, and I can't argue against.</div><div class=""><br class=""></div><div class="">— Pyry</div><div class=""><br class=""></div><div class="">Epilogue: The parallel Swiftverse, however, went their own way and protected fellow swiftizens against indecision with:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">enum</span> Nope {}</div></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@available</span>(*, deprecated,</div><div style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> message=</span>"Your unwrappingness gets nowhere less Optional. See?"<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> ** <T>(x: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>?, y: <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span>?) -> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Nope</span> { <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">fatalError</span>(<span style="color: rgb(209, 47, 27);" class="">"How embarrassing!"</span>) }</div></div></blockquote><font face="Menlo" class=""><br class=""></font><div class="">Who knows, maybe one day they went on and invented a way to turn that thing into a compiler error? Who knows.</div><div class=""><br class=""></div><div class="">The End.</div></body></html>