<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="">On Jan 19, 2016, at 10:03 AM, Thorsten Seitz <<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>> wrote:<br class=""><div><blockquote type="cite" class=""><br class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">Am 19.01.2016 um 06:28 schrieb Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;">If you extend the same analogy to switch, then the most important cases are when the pattern being matched and the values being processed are lexically small, and have few cases. We have a lot of syntactic sugar for processing optionals (e.g. if/let, the ?? operator, etc), but ?? for example doesn’t apply to general pattern matching. With the expression above, for example, you could match on an enum analogously to the ?? operator like this:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;"><font face="Menlo" class="">result = someEnum ? case .SomeCase(let x): x, default: y</font></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;">If you compare that to a switch statement, I can see how that could be compelling. OTOH, the larger the expression (the more cases) and the more complex the patterns, the better a switch statement starts to look.</div></div></blockquote></div><br class=""><div class="">For me the killer feature is not being able to write it inline, it is making it clear that an assignment happens, i.e.</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">let result = someEnum ?</font></div><div class=""><font face="Menlo" class=""> case .SomeCase(let x): x</font></div><div class=""><font face="Menlo" class=""> default: y</font></div><div class=""><br class=""></div><div class="">is IMO much more readable (= allowing to instantly see what’s going on) than</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">let result</font></div><div class=""><font face="Menlo" class="">switch someEnum {</font></div><div class=""><font face="Menlo" class="">case .SomeCase(let x): result = x</font></div><div class=""><font face="Menlo" class="">default: result = y</font></div><div class=""><font face="Menlo" class="">}</font></div></div></div></blockquote><div><br class=""></div><div>Yes, I agree with you.</div><br class=""><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">For the same reason</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">let result = match(someEnum) {</font></div><div class=""><font face="Menlo" class=""> case .SomeCase(let x): x</font></div><div class=""><font face="Menlo" class=""> default: y</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><br class=""></div><div class="">would be just as appealing to me. For using this as a switch-expression I’m strongly against introducing a special map method for basic types, though and rather propose to use a global function „match“ (more on that further below).</div><div class=""><br class=""></div><div class=""><div class="">The inline version (if desired) is not too different from the ?-based switch-expression:</div><div class=""><br class=""></div><div class="">let result = match(someEnum) { case .SomeCase(let x): x; default: y }</div></div></div></blockquote><div><br class=""></div><div>Yes, after reading this again, I agree that just taking ‘match’ (or something like it) as a keyword and making it be a proper switch expression (with braces) is probably the right way to go. Overloading ?: is gross :-)</div><div><br class=""></div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The big advantage of the partial function proposal would be that it is much more general as it is usable everywhere a unary function argument is used, i.e. for map etc.</div></div></blockquote></div><br class=""><div class="">Sure, you’re optimizing for one specific case at the expense of composability. I personally don’t find that compelling, but YMMV.</div><div class=""><br class=""></div><div class="">We’re somewhat unlikely to add a single syntax for switch expressions, but I find it inconceivable that we would add partial functions AND switch expressions. This isn’t a case where “both are potentially interesting, so lets have both” - this is a situation where we (as a community) would have to pick one or the other.</div><div class=""><br class=""></div><div class="">-Chris</div></body></html>