<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="">I prefer patterns and matching cases have a many-to-one relation.<div class=""><br class=""></div><div class="">Keep in mind, our goal is to make match site more readable/teachable. I’d venture to say that given the definition of “Color”, this pattern is really unreadable. So is this kind of attempt to disambiguate, if we allow mixture of long/short forms:</div><div class=""><br class=""></div><div class="">case .color(hue: _, _, let alpha): // yuck</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><div><blockquote type="cite" class=""><div class="">On Apr 2, 2017, at 11:46 PM, Brent Royal-Gordon <<a href="mailto:brent@architechies.com" class="">brent@architechies.com</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=""><blockquote type="cite" class=""><div class="">On Apr 2, 2017, at 11:17 PM, Daniel Duan 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=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Apr 2, 2017, at 11:10 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>> wrote:</div><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">This rule cannot hold. You cannot have the shorthand syntax you propose, disallow mixing of shorthand syntax and the longer form, *and* allow `_` to substitute for any pattern without a label.</div><div class=""><br class=""></div><div class="">```</div><div class="">enum E {</div><div class=""> case foo(a: Int, b: Int, c: Int)</div><div class=""> case foo(a: String, c: String, e: String)</div><div class="">}</div><div class=""><br class=""></div><div class="">let e = /* instance of E */</div><div class=""><br class=""></div><div class="">switch e {</div><div class="">case foo(let a, _, _):</div><div class=""> // what type is `a` here?</div><div class=""> break</div><div class="">default:</div><div class=""> fatalError()</div><div class="">}</div><div class="">```</div></div></div></div></div></blockquote></div></div></div></div></div></blockquote></div><div class=""><blockquote type="cite" class=""><br class=""></blockquote></div><div class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">That seems like straight up ambiguity with or without restriction on the label though? This kind of usability problem should and is discouraged by the proposed solution.<div class=""><div class=""><div class=""><blockquote type="cite" class=""></blockquote></div></div></div></div></blockquote><br class=""></div><div class="">Let's make it a little more reasonable:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>enum Color {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case color(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>case color(hue: CGFloat, saturation: CGFloat, value: CGFloat, alpha: CGFloat)</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let c: Color = …</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>switch c {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>case .color(_, _, _, let alpha):</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>…</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">Interestingly, in this example it would probably be appropriate to match both cases. I wonder if that's true in the general case.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">-- </div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>
</div>
<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>