I do like the idea of leaving the if else as an statement because it may simplify things. Ideally the new ternary syntax would exclude the question mark and colon. Without introducing new keywords, it could work something like the following. <div><br></div>let result = where condition switch x else y<div><br></div><div>let result2 = where x < y switch 1 else where y == x switch 2 else 3</div><div><br></div><div><br><div><div><br></div><div><br><div><br><br>On Sunday, December 6, 2015, Alex Lew via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What if we left the if { ...} else { ... } syntax alone (as a statement), and updated the ternary expression to be a more general pattern matching expression (closer to "switch")? Something like<div><br></div><div>let x = condition ?</div><div> true: "Hello"</div><div> false: "Goodbye"</div><div><br></div><div>let x = optionalValue ?</div><div> .Some(let unwrapped): "Hello, \(unwrapped)"</div><div> .None: "To Whom It May Concern"</div><div><br></div><div>let myFavoriteColor = yourFavoriteColor ?</div><div> .Blue: .Red</div><div> .Green: .Blue</div><div> .Red: .Green</div><div><br></div><div>let quadrant = (x, y) ?</div><div> let (x, y) where x < 50 && y < 50: "top left"</div><div> let (x, y) where x < 50 && y > 50: "bottom left"</div><div> let (x, y) where x > 50 && y < 50: "top right"</div><div> default: "bottom right"</div><div><br></div><div>The colon comes from the fact that this is sort of a light-weight expression-based "switch" statement, where each branch can only contain an expression, not a series of statements.</div><div><br></div><div>This is very similar to pattern matching expressions in languages like Haskell, ML, and Coq.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 6, 2015 at 11:25 AM, Thorsten Seitz <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','thorsten.seitz@web.de');" target="_blank">thorsten.seitz@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span><blockquote type="cite"><div>Am 06.12.2015 um 01:28 schrieb Alex Lew via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a>>:</div><br><div><div dir="ltr">I don't think you can just get rid of the if statement in favor of an expression. You still want to be able to do this:<div><br></div><div>if (condition) {</div><div> funcWithSideEffectsThatReturnsInt()</div><div>} else {</div><div> funcWithSideEffectsThatReturnsString()</div><div>}</div><div><br></div><div>but that's not a valid expression (what is its type?).</div></div></div></blockquote><div><br></div></span><div>That would actually be no problem if Swift’s type system would have union types (Ceylon has union and intersection types which are quite awesome and enable lots of nice things quite naturally, see <a href="http://ceylon-lang.org/documentation/1.2/tour/types/" target="_blank">http://ceylon-lang.org/documentation/1.2/tour/types/</a>).</div><div><br></div><div>In that case the type of such an expression would just be the union of both types, which is written <font face="Courier">Int | String</font> in Ceylon.</div><span><font color="#888888"><div><br></div><div>-Thorsten</div></font></span></div><br></div></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=OWK4tSasaK2n-2FQIIcS9Ug-2FuFXG-2BJ3z6cFMLgm306hDeMsRXzmJqGfGJ9G-2Fehbead16nhv-2B5I3Li4BWA8sVmRhnJOu73Lg2HUoquA1MHdOFUWO1C5aD2n4NCTjLbVR8NuqSGRdHk9jzgWm8N660cvFiD0CGN-2Fg71Bq2YHIK71OIoJ-2BNO7KFjR88KoQXH8rn91KzCV6HOj-2F3gLPRGYWs5Eubu-2FwWju-2FxLZVcirIfyORD8-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</blockquote></div></div></div></div>