<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Thanks for the thoughtful feed Xiaodi! Replies are inline. I'm going to incorporate some of the responses into the proposal.</div><div id="AppleMailSignature"><br></div><div>On Mar 8, 2017, at 9:56 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra">The rendered version differs from the text appended to your message. I'll assume the more fully fleshed out version is what you intend to submit. Three comments/questions:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'">Enum Case "Overloading"</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">An enum may contain cases with the same full name but with associated values of different types. For example:</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Expr</span> {
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">literal</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Bool</span>)
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">literal</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Int</span>)
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">The above cases have overloaded constructors, which follow the same rules as functions at call site for disambiguation:</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> It's clear which case is being constructed in the following.</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> aBool<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> Expr <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">literal</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">false</span>)
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> anInt<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">:</span> Expr <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">literal</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">42</span>)</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">User must specify an <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">as</code> expression in sub-patterns in pattern matching, in order to match with such cases:</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">literal</span>(<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> value) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> this is ambiguous</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">literal</span>(<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> value <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">as</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">Bool</span>) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> matches `case literal(Bool)`</span></pre></div><div class="gmail_extra"><br></div>Comment/question 1: Here, why aren't you proposing to allow `case .literal(let value: Bool)`? For one, it would seem to be more consistent. </div></div></div></blockquote><div><br></div><div>The example in proposal doesn't include any labels. Are you suggesting two colons for sub-patterns with labels? Like `case .literal(value: let value: Bool)`? This looks jarring. But I'm definitely open to other suggestions.</div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra">Second, since we still have some use cases where there's Obj-C bridging magic with `as`, using `as` in this way may run into ambiguity issues if (for example) you have two cases, one with associated value of type `String` and the other of type `NSString`.</div></div></div></blockquote><div><br></div><div>Either this should be rejected at declaration, or we need a way to accept a "pre-magic" resolution at pattern matching, when this scenarios is at hand. I'm on the phone so I can't verify. Wouldn't function overloading face a similar problem?</div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"> Also, since enum cases are to be like functions, I assume that the more verbose `as` version would work for free: `case .literal(let value) as (Bool) -> Expr`?</div><div class="gmail_extra"><br></div></div></div></blockquote><div><br></div>This is not being proposed. When a user sees/authors a case, their expectation for the declared case constructor should resemble that of a function. Pattern matching was considered separately since it's not relatable syntactically.<br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><a id="gmail-user-content-alternative-payload-less-case-declaration" class="gmail-anchor" href="https://github.com/dduan/swift-evolution/blob/SE0155-rev2/proposals/0155-normalize-enum-case-representation.md#alternative-payload-less-case-declaration" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Alternative Payload-less Case Declaration</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">In Swift 3, the following syntax is valid:</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Tree</span> {
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">leaf</span>() <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> the type of this constructor is confusing!</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span>}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><code style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">Tree.leaf</code> has a very unexpected type to most Swift users: <code style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(27,31,35,0.0470588);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">(()) -> Tree</code></p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">We propose this syntax declare the "bare" case instead. So it's going to be the equivalent of</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Tree</span> {
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">leaf</span> <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> `()` is optional and does the same thing.</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span>}</pre></div><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal"><br></span></h3><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">Comment/question 2: First, if associated values are not to be modeled as tuples, for backwards compatibility </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">the rare uses of `case leaf()` should be migrated to `case leaf(())`.</span></h3></div></div></div></blockquote><div>Yes, and when user uses a arbitrary name when they should have used a label, or when labels are misspelled, the compiler should suggest the correct labels. I wasn't sure how much of migrator related thing should go into a proposal. Perhaps there should be more.</div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">Second, </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">to be clear, you are _not_ proposing additional sugar so that a case without an associated value be equivalent to a case that has an associated value of type `Void`, correct? You are saying that, with your proposal, both `case leaf()` and `case leaf` would be regarded as being of type `() -> Tree` instead of the current `(()) -> Tree`?</span></h3></div></div></div></blockquote><div>Correct. I'm _not_ proposing implicit `Void`.</div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">[The latter (i.e. `() -> Tree`) seems entirely fine. The former (i.e. additional sugar for `(()) -> Tree`) seems mostly fine, except that it would introduce an inconsistency with raw values that IMO is awkward. That is, if I have `enum Foo { case bar }`, it would make case `bar` have implied associated type `Void`; but, if I have `enum Foo: Int { case bar }`, would case `bar` have raw value `0` of type `Int` as well as associated value `()` of type `Void`?]</span><br></h3><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal"><br></span></div><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><a id="gmail-user-content-pattern-consistency" class="gmail-anchor" href="https://github.com/dduan/swift-evolution/blob/SE0155-rev2/proposals/0155-normalize-enum-case-representation.md#pattern-consistency" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1"></a>Pattern Consistency</h3><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><em style="box-sizing:border-box">(The following enum will be used throughout code snippets in this section).</em></p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">indirect</span> <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">enum</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">Expr</span> {
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">variable</span>(<span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">name</span></span>: <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>)
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">lambda</span>(<span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">parameters</span></span>: [<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">String</span>], <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">body</span></span>: Expr)
}</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">Compared to patterns in Swift 3, matching against enum cases will follow stricter rules. This is a consequence of no longer relying on tuple patterns.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">When an associated value has a label, the sub-pattern must include the label exactly as declared. There are two variants that should look familiar to Swift 3 users. Variant 1 allows user to bind the associated value to arbitrary name in the pattern by requiring the label:</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">variable</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">name</span>: <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> okay</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">variable</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">x</span>: <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> compile error; there's no label `x`</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">lambda</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">parameters</span>: <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> params, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">body</span>: <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> body) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> Okay</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">lambda</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">params</span>: <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> params, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">body</span>: <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> body) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> error: 1st label mismatches</span></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">User may choose not to use binding names that differ from labels. In this variant, the corresponding value will bind to the label, resulting in this shorter form:</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">variable</span>(<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> name) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> okay, because the name is the same as the label</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">lambda</span>(<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> parameters, <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> body) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> this is okay too, same reason.</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">variable</span>(<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> x) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> compiler error. label must appear one way or another.</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">lambda</span>(<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> params, <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> body) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> compiler error, same reason as above.</span></pre></div><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">Comment/question 3: </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">Being a source-breaking change, that requires extreme justification, and I just don't think there is one for this rule. </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">The perceived problem being addressed (that one might try to bind `parameters` to `body` and `body` to `parameters`) is unchanged whether enum cases are modeled as tuples or functions, so aligning enum cases to functions is not in and of itself justification to revisit the issue of whether to try to prohibit this. </span></h3></div></div></div></blockquote><div>To reiterate, here patterns are changed not for any kind of "alignment" with function syntax. It changed because we dropped the tuple pattern (which remains available for matching with tuple values, btw), therefore we need to consider what a first-class syntax for enum case would look like.</div><div><br></div><div>The justification for this breaking change is this: with tuples, labels in pattern is not well enforced. User can skip them, bind value to totally arbitrary names, etc. I personally think emulating such rule prevents us from making pattern matching easier to read for experienced devs and easier to learn for new comers. </div><div><br></div><div>It's reasonable to expect existing patterns in the wild either already use the labels found in declaration or they are matching against label-less cases. In other words, existing code with good style won't be affected much. For the code that actually would break, I think the migrator and the compiler can provide sufficient help in form of migration/fixits/warnings.</div><div><br></div><div>Ultimately I think requiring appearance of labels one way or another in patterns will improve both the readability of the pattern matching site as well as forcing the author of case declaration consider the use site more.</div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">In fact, I think the proposed solution suffers from two great weaknesses.</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal"> First, it seems ad-hoc. Consider this: i</span><span style="font-family:arial,sans-serif;font-size:small;font-weight:normal;color:rgb(34,34,34)">f enum cases are to be modeled as functions, then I should be able to write something intermediate between the options above; namely: `case .variable(name:)(let x)`. Since `.variable` unambiguously refers to `.variable(name:)`, I should also be allowed to write `.variable(let x)` just as I am now.</span></h3></div></div></div></blockquote>Again, patterns are not to be modeled after functions. Only the declaration and usage of case constructors are.<br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;font-size:1.25em;line-height:1.25;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><span style="font-family:arial,sans-serif;font-size:small;font-weight:normal;color:rgb(34,34,34)"> Second</span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">, it </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">seems unduly restrictive. If, in the containing scope, I have a variable named `body` that I don't want to shadow, this rule would force me to either write the more verbose form or deal with shadowing `body`. </span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal">If a person opts for the shorter form, they are choosing not to use the label.</span></h3></div></div></div></blockquote><div>In fact this (to avoid label conflict in nesting) is the only reason the longer form allows rebinding to other names at all! You say "unduly restrictive", I say "necessarily flexible" :)</div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-weight:normal"><br></span></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">Only one of these variants may appear in a single pattern. Swift compiler will raise a compile error for mixed usage.</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">lambda</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">parameters</span>: <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> params, <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> body) <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> error, can not mix the two.</span></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px">Some patterns will no longer match enum cases. For example, all associated values can bind as a tuple in Swift 3, this will no longer work after this proposal:</p><div class="gmail-highlight gmail-highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px;color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol';font-size:16px"><pre style="box-sizing:border-box;font-family:sfmono-regular,consolas,'liberation mono',menlo,courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="gmail-pl-c" style="box-sizing:border-box">//</span> deprecated: matching all associated values as a tuple</span>
<span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">case</span> <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> .<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">lambda</span>(f) <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> anLambdaExpr {
<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">evaluateLambda</span>(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">parameters</span>: f.<span class="gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">parameters</span>, <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">body</span>: f.<span class="gmail-pl-smi" style="box-sizing:border-box;color:rgb(51,51,51)">body</span>)
}</pre><div><br></div></div><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(234,236,239);color:rgb(36,41,46);font-family:-apple-system,blinkmacsystemfont,'segoe ui',helvetica,arial,sans-serif,'apple color emoji','segoe ui emoji','segoe ui symbol'"><a id="gmail-user-content-source-compatibility" class="gmail-anchor" href="https://github.com/dduan/swift-evolution/blob/SE0155-rev2/proposals/0155-normalize-enum-case-representation.md#source-compatibility" style="box-sizing:border-box;background-color:transparent;color:rgb(3,102,214);text-decoration:none;float:left;padding-right:4px;line-height:1"></a></h2></div></div>
</div></blockquote></body></html>