<div dir="ltr">It looks like it's a bit more complicated than that. I just tried a few cases in the REPL:<div><br></div><div>```</div><div><div>let t1 = (a: 5, b: true)</div><div>let t2 = (5, b: true)<br></div><div><br></div><div>// equality testing works</div><div><div>t1 == t2 // works: $R0: Bool = true</div><div><br></div></div><div>// assignment in both directions works (missing label -> has label and has label -> missing label)</div><div><div>let t3: (Int, b: Bool) = t1 // works: t3: (Int, b: Bool) = { 0 = 5, b = true }</div><div><div>let t4: (a: Int, b: Bool) = t2 // works: t4: (a: Int, b: Bool) = { a = 5, b = true }</div><div><br></div></div><div>// switch expression has labels, case patterns are missing some:</div><div><div>switch t1 {</div><div>case (5, b: true): print("works") </div><div>default: print("doesn't work") </div><div>} </div><div>// works: prints "works"</div><div><br></div></div></div></div><div>// switch expression is missing a label, case pattern has all of them:</div><div><div>switch t2 {</div><div>case (a: 5, b: true): print("works") </div><div>default: print("doesn't work") </div><div>} </div><div>// error: repl.swift:11:7: error: tuple pattern element label 'a' must be '_'</div><div>// case (a: 5, b: true): print("works")</div><div>// ^</div><div>```</div></div><div><br></div><div>So is this an inconsistency in the way tuples are handled there?</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jan 2, 2017 at 12:17 AM Derrick Ho <<a href="mailto:wh1pch81n@gmail.com">wh1pch81n@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In your first example the switch statement is evaluating whether the given tuple of type (_:bool, _:bool) matches another tuple of type (_: bool, y: bool)<br class="gmail_msg"><br class="gmail_msg">The type signature doesn't match.<br class="gmail_msg"><br class="gmail_msg">I believe the change would not be additive like you say because it seems like it would require a change in how tuple compare with each other. <br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Mon, Jan 2, 2017 at 12:00 AM Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">Well, it turns out, I was testing it on already established values. The first of the following two examples works but the second does not.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">switch</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg"> (</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">true</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">, y: </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">false</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">) {</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">case</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg"> (</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">true</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">, y: </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">false</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">): </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">"tf"</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">)</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">default</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">: </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">"nope"</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">)</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">}</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;min-height:21px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"></span><br class="gmail_msg"></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">let</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> testTuple2 = (</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">true</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">false</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">)</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;min-height:21px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"></span><br class="gmail_msg"></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">switch</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">testTuple2</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg"> {</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// error: tuple pattern element label 'y' must be '_'</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">case</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg"> (</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">true</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">, y: </span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">false</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">): </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">"tf"</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">)</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo;color:rgb(186,45,162)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">default</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">: </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81" class="gmail_msg">print</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">"nope"</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000" class="gmail_msg">)</span></div><div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">}</span></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I think this gets a 95% Emily Litella (<a href="https://en.wikipedia.org/wiki/Emily_Litella" class="gmail_msg" target="_blank">https://en.wikipedia.org/wiki/Emily_Litella</a>). "Nevermind."</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">And thanks, Tony,</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">-- E</div></div><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">On Jan 1, 2017, at 8:49 PM, Tony Allevato <<a href="mailto:tony.allevato@gmail.com" class="gmail_msg" target="_blank">tony.allevato@gmail.com</a>> wrote:</div><br class="m_8577646088439372273m_3891741560682417830Apple-interchange-newline gmail_msg"><div class="gmail_msg"><div dir="ltr" class="gmail_msg">The "after" example you posted seems to work already in Swift today. Is there something I'm missing?<div class="gmail_msg"><br class="gmail_msg"></div></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Sun, Jan 1, 2017 at 7:35 PM David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">Sent from my iPhone</div></div><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg">On Jan 1, 2017, at 19:25, Erica Sadun via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"><div class="gmail_msg">Was helping a friend with some code and got inspired. I decided to throw this on list to see if there's any traction. <div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><b class="gmail_msg">Idea</b>: Introduce optional argument labels to tuples in switch statements</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><b class="gmail_msg">Motivation</b>: Cases can be less readable when pattern matching tuples. Semantically sugared, optional argument labels could increase readability for complex `switch` statements by incorporating roles into cases.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Here's an example before:</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">fileprivate func chargeState(for battery: BatteryService)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> -> ChargeState</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">{</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> switch (battery.state, battery.isCalculating) {</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, true):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .calculating(isDischarging: false)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, _) where battery.isCharging:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .charging</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, _):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .acPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (_, true):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .calculating(isDischarging: true)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> default:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .batteryPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> }</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">and after:</div><div class="gmail_msg"><br class="gmail_msg"></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">fileprivate func chargeState(for battery: BatteryService)</font></div></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> -> ChargeState</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">{</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> switch (battery.state, <b class="gmail_msg">calculating: battery.isCalculating</b>) {</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, <b class="gmail_msg">calculating: true</b>):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .calculating(isDischarging: false)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, _) where battery.isCharging:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .charging</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (.isACPowered, _):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .acPower</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> case (_, <b class="gmail_msg">calculating: true</b>):</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .calculating(isDischarging: true)</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> default:</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> return .</font><span style="font-family:Menlo" class="gmail_msg">batteryPower</span></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg"> }</font></div></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div></div></blockquote><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">It's a pretty minor change, and I could see it being added to allow case statements to be more readable with a minimal change to the compiler. I also have a back-burnered proposal I intend to introduce in Phase 2 that would introduce Boolean raw value enumerations for flags.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thoughts?</div></div></blockquote><br class="gmail_msg"></div><div dir="auto" class="gmail_msg"><div class="gmail_msg">I can't think of a reason not to do that... +1</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">- Dave Sweeris</div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>
</div></blockquote></div><br class="gmail_msg"></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>
</blockquote></div>