<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>This would be a real loss 😔. Another nice thing we would be losing is tuple field labels *after* matching:</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">if case let .bar(a) = Foo.bar(x: Int, y: Int) {</div><div id="AppleMailSignature">&nbsp; doThings(with: a.x, a.y)</div><div id="AppleMailSignature">}</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Keeping them means we have the create a special (reverse)splatting rule for pattern matching. I can see a few arguments against this:</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">1. It's a cost in complexity that pays for some niche convenience (or not? Real-world usage research needed)</div><div id="AppleMailSignature">2. It can be added later without introducing source-breakage (but keeping it means less source-breakage after this proposal, again, depends on usage in the wild).</div><div id="AppleMailSignature">3. Depends on whether splatting comes up in the future, we may want to relate the syntax here and there.</div><div id="AppleMailSignature">4. As Tony mentioned, auto-deriving equitable could lead to eventual glory.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">I was convinced to keep the feature after reading your example but now I'm not sure again. Grrrr.</div><div><br>On Jan 22, 2017, at 7:42 AM, T.J. Usiyan &lt;<a href="mailto:griotspeak@gmail.com">griotspeak@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Implementing equality would be made tedious again if we lose this.<div><br></div><div>```</div>enum Jams : Equatable {<br><br>&nbsp; &nbsp; case dmsr(Bool)<br>&nbsp; &nbsp; case kiss(Bool, Bool)<br>&nbsp; &nbsp; case pheromone(Int, Bool, Int)<br><br><br>&nbsp; &nbsp; public static func ==(lhs:Jams, rhs:Jams) -&gt; Bool {<br>&nbsp; &nbsp; &nbsp; &nbsp; switch (lhs, rhs) {<br>&nbsp; &nbsp; &nbsp; &nbsp; case let (.dmsr(left), .dmsr(right)):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return left == right<br>&nbsp; &nbsp; &nbsp; &nbsp; case let (.kiss(left), .kiss(right)):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return left == right<br>&nbsp; &nbsp; &nbsp; &nbsp; case let (.pheromone(left), .pheromone(right)):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return left == right<br>&nbsp; &nbsp; &nbsp; &nbsp; case (.dmsr, _), (.kiss, _), (.pheromone, _):<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<div>```<br><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 22, 2017 at 4:51 AM, Robert Widmann via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><span></span></div><div><div>Sure.&nbsp; One of the first gadgets I wrote was a way of destructuring an array into a familiar cons-list kind of enum (<a href="https://github.com/typelift/Basis/blob/master/Basis/Array.swift#L9" target="_blank">https://github.com/typelift/<wbr>Basis/blob/master/Basis/Array.<wbr>swift#L9</a>) which you use something like this with other non-trivial enums (<a href="https://github.com/typelift/Valence/blob/cf4353c64de93b98c460529b06b8175c9ecfb79b/Tests/SystemF.swift#L161" target="_blank">https://github.com/typelift/<wbr>Valence/blob/<wbr>cf4353c64de93b98c460529b06b817<wbr>5c9ecfb79b/Tests/SystemF.<wbr>swift#L161</a>).</div><div><br></div><div>It's not strictly a problem for me to lose this feature, but it is gonna be a bit weird if we lose recursive match but also allow it for just plain old tuple patterns.</div><div><br><div>~Robert Widmann</div></div><div><br>2017/01/22 3:02、Daniel Duan &lt;<a href="mailto:daniel@duan.org" target="_blank">daniel@duan.org</a>&gt; のメッセージ:<br><br></div><div><div class="h5"><blockquote type="cite"><div>FWIW, in all public Github repos with 5k+ stars whose language gets recognized as “Swift”, 576 enum cases has associated values and among them 55 has 2 values or more. After some very casual grepping I didn’t find a lot of usage of this particular pattern.<div><br></div><div>Care to share some examples, Robert?</div><div><br></div><div>- Daniel Duan</div><div><br><div><div><blockquote type="cite"><div>On Jan 21, 2017, at 11:00 PM, Robert Widmann &lt;<a href="mailto:devteam.codafi@gmail.com" target="_blank">devteam.codafi@gmail.com</a>&gt; wrote:</div><br class="m_4667549732735053882Apple-interchange-newline"><div><div dir="auto"><div>I find myself doing this <i>a lot</i>, but maybe my problems are just more Algebra-shaped than most.&nbsp; That said, I appreciate this cleanup and lean +1 (because you mentioned a way to partly keep this behavior).</div><div><br></div><div>~Robert Widmann</div><div><br>2017/01/19 18:14、Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; のメッセージ:<br><br></div><blockquote type="cite"><div><span></span><br><blockquote type="cite"><span>On Jan 19, 2017, at 2:58 PM, Daniel Duan &lt;<a href="mailto:daniel@duan.org" target="_blank">daniel@duan.org</a>&gt; wrote:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><blockquote type="cite"><span>On Jan 19, 2017, at 2:29 PM, Joe Groff &lt;<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>&gt; wrote:</span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>On Jan 19, 2017, at 1:47 PM, Douglas Gregor via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>This looks totally reasonable to me. A couple of comments:</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><span>1) Because this proposal is breaking the link between the associated value of an enum case and tuple types, I think it should spell out the rules that switch statements will use when matching an enum value against a a case with an associated value. Some kind of rules fell out of them being treated as tuple types, but they might not be what we want.</span><br></blockquote></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span></span><br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><span>I was about to bring up the same. Right now, an enum pattern works like .&lt;identifier&gt; &lt;tuple-pattern&gt;, where the &lt;tuple-pattern&gt; then recursively matches the payload tuple. In this model, it seems like we'd want to treat it more like .&lt;identifier&gt;(&lt;pattern&gt;, &lt;pattern&gt;, ...). Similar to how we lost "tuple splatting" to forward a bunch of arguments, we'd have to decide whether we lose the ability to match all parts of the payload into a tuple.</span><br></blockquote></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>I’m leaning towards “no” for simplicity of the language (and implementation). That means this would be source-breaking 😞.&nbsp; Will update the proposal and see how the rest of the feedback goes.</span><br></blockquote><span></span><br><span>It'd be a good idea to try to find examples of people doing this out in the wild too, to see how widespread it is as well as how onerous the workarounds for losing the feature would be.</span><br><span></span><br><span>-Joe</span><br><span></span><br><span>______________________________<wbr>_________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a></span><br></div></blockquote></div></div></blockquote></div><br></div></div></div></blockquote></div></div></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>
</div></blockquote></body></html>