<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><blockquote type="cite"><div class=""><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">NSDictionary* switch = @{</span></font></div><div class=""><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><span class="Apple-tab-span" style="white-space: pre;">        </span>@[@0,@1]: ^{ NSLog(@"zero one"); },<span class="Apple-tab-span" style="white-space: pre;">        </span></span></font></div><div class=""><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><span class="Apple-tab-span" style="white-space: pre;">        </span>@[@1,@1]: ^{ NSLog(@"one one"); }</span></font></div><div class=""><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">};</span></font></div></blockquote></div><div><br></div><div>What you're describing here is only a narrow use of switch statements and doesn't handle the most powerful features of the switch statement: pattern matching.&nbsp;</div><div><br></div><div>How would you go about&nbsp;</div><div>Switch (optional, superclass, genericStruct) {</div><div>&nbsp; &nbsp; Case (let value?, let sub as SubClass, Generic&lt;ConcreteType&gt;: // use all this stuff</div><div>&nbsp; &nbsp; case _: // nothing matches</div><div>}</div><div><br></div><div>You don't seem familiar with switches and tuple deconstruction so here is a common everyday use case: prepare segues between view controllers:</div><div><br></div><div><span style="background-color: rgba(255, 255, 255, 0);"><span class="pl-k" style="box-sizing: border-box;">func</span> <span class="pl-en" style="box-sizing: border-box;">prepareFor<span style="box-sizing: border-box; padding: 2px; margin: 0px -2px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">Segue</span></span>(<span class="pl-en" style="box-sizing: border-box;"><span class="pl-smi" style="box-sizing: border-box;"><span style="box-sizing: border-box; padding: 2px; margin: 0px -2px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">segue</span></span></span>: UIStoryboard<span style="box-sizing: border-box; padding: 2px; margin: 0px -2px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">Segue</span>, <span class="pl-en" style="box-sizing: border-box;"><span class="pl-smi" style="box-sizing: border-box;">sender</span></span>: <span class="pl-c1" style="box-sizing: border-box;">Any</span><span class="pl-k" style="box-sizing: border-box;">?</span>) {</span></div><div>&nbsp; &nbsp; Switch (segue.identifier, segue.destination, sender) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Case ("Segue"?, let vc as FirstVC, .some(.enumType(let value)) ): // prepare the vc</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ... // other segues</div><div>&nbsp; &nbsp; }</div><div>}<br><br><blockquote type="cite"><div class=""><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">So its not like this is some kind of key feature.&nbsp;</span></font></div></blockquote>Dictionaries require their keys to be hashable. That's a problem with exhausitveness checking. A hashable Type has infinite cardinality and as such, can't be exhaustive. Therefore the compiler will never be able to check the completeness of your switch statement, throwing away one the languages key feature: safety.&nbsp;</div><div><br></div><div>I think we should steer this conversation back to tuple labels.&nbsp;</div><div><br><div>Andre Videla&nbsp;</div></div><div><br>On 11 Jan 2017, at 08:11, Freak Show via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 7, 2017, at 23:37, Derrick Ho &lt;<a href="mailto:wh1pch81n@gmail.com" class="">wh1pch81n@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">I think pattern matching is the most compelling reason to keep tuples.<span class="Apple-converted-space">&nbsp;</span><span class="Apple-converted-space">&nbsp;</span></span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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;" class=""><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">If they were gone, how would we replace the following?</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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;" class=""><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">switch (a, b) {</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">case (value1, value2):</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">case (value3, value4):</span><br style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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;" class=""><span style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">}</span></div></blockquote></div><br class=""><div class="">I meant to mention this: &nbsp;Smalltalk - Objective C's mother language - has no switch statement (or 'if' or loops either). &nbsp;The language is incredibly malleable because it only does one thing - send messages to objects and all the language constructs are in the library. &nbsp;It would take very little time to add one. &nbsp;Off and on someone does it as an exercise but it never sticks.</div><div class=""><br class=""></div><div class="">Instead, you just use a dictionary of closures. &nbsp;An Objective C equivalent might be:</div><div class=""><br class=""></div><div class="">NSDictionary* switch = @{</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>@[@0,@1]: ^{ NSLog(@"zero one"); },<span class="Apple-tab-span" style="white-space: pre;">        </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>@[@1,@1]: ^{ NSLog(@"one one"); }</div><div class="">};</div><div class=""><br class=""></div><div class="">NSArray* pair = @[@3, @5];</div><div class=""><br class=""></div><div class="">(switch at:pair ifAbsent:^{})(); &nbsp;//where at:ifAbsent: is added in the Smalltalk style as an extension.</div><div class=""><br class=""></div><div class="">The Smalltalk equivalent (much less ugly because of the lack of @'s) is</div><div class=""><br class=""></div><div class="">&nbsp;switch := {</div><div class="">&nbsp; #(0 1) &nbsp; -&gt; [ Transcript nextPutAll: 'zero one' ] .</div><div class="">&nbsp; #(1 1) &nbsp; -&gt;&nbsp;[ Transcript nextPutAll: 'one one' ] .&nbsp;</div><div class="">&nbsp; #(1 2) -&gt; [ Transcript nextPutAll: 'one two' ] .</div><div class="">} asDictionary.</div><div class=""><br class=""></div><div class="">(switch at: pair ifAbsent:[ [] ]) value.</div><div class=""><br class=""></div><div class="">So its not like this is some kind of key feature. &nbsp;Switch's vs dictionaries of closures - pretty much the same thing as pattern matching goes. &nbsp;The only thing you have to do is put an object at key that identifies itself as equal to the pattern you will throw at it.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></body></html>