<div><br><div class="gmail_quote"><div dir="auto">On Thu, Jan 4, 2018 at 18:39 Cheyo J. Jimenez <<a href="mailto:cheyo@masters3d.com">cheyo@masters3d.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Jan 4, 2018, at 2:55 PM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> wrote:</div><br class="m_-8595388434919151480Apple-interchange-newline"><div><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br class="m_-8595388434919151480Apple-interchange-newline">On Thu, Jan 4, 2018 at 17:15 Cheyo J. Jimenez <<a href="mailto:cheyo@masters3d.com" target="_blank">cheyo@masters3d.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Jan 4, 2018, at 11:53 AM, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> wrote:</div><br class="m_-8595388434919151480m_-6520709161405088222Apple-interchange-newline"><div><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br class="m_-8595388434919151480m_-6520709161405088222Apple-interchange-newline">On Thu, Jan 4, 2018 at 13:46 Cheyo Jimenez <<a href="mailto:cheyo@masters3d.com" target="_blank">cheyo@masters3d.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div></div><div><br></div><div><br>On Jan 4, 2018, at 10:49 AM, Jordan Rose <<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>> wrote:<br><br></div><blockquote type="cite"><div>I'll admit I hadn't thought of using "unknown default" (or "default unknown"). I don't think that's terrible, but I mildly prefer `unknown case` because it builds on the "pun" that enum elements are also defined using 'case'. If anything hits this part of the switch, it really will be an "unknown case", i.e. a statically-unknown enum element.<div><br></div><div>To Cheyo's point, if this<span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span><i>were</i> to be a single token I'd probably spell it #unknown, like #available. Then we'd have `case #unknown:` and something that naturally expands to other pattern positions. I found that less aesthetically pleasing, though, and so a context-sensitive keyword seemed like the way to go.</div><div><br></div><div>(For the record, though, I wouldn't describe `case _` as a special case of `default`. They do exactly the same thing, and `_` is a useful pattern in other contexts, so if anything the current `default` should be thought of as syntactic sugar for `case _`.)</div></div></blockquote><div><br></div></div><div dir="auto"><div>Can case _ be mixed with unknown case? How can we match all compile time known cases but exclude future cases?</div></div></blockquote><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">What’s your use case for that? That eliminates the possibility of “unknown case” giving you compile-time warnings for subsequently added cases, which was the entire purpose of adding the syntax in the first place.</div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div><div>I was thinking of a generalized `unknown case` pattern but that is <a href="https://github.com/apple/swift-evolution/pull/777/files#diff-a68dc745ee86d09566b232b6954c5158R321" target="_blank">out of scope for this proposal.</a> </div><div><div><br></div><div><div>switch excuse {</div><div> case .eatenByPet :</div><div> //…</div><div> unknown case:</div><div> // …</div><div> case _:</div><div> // …</div><div> }</div></div></div><br><blockquote type="cite"><div><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><blockquote class="gmail_quote" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>Should there be something like `case *` that would capture all currently known cases during compile time? case * and case _ would be the same in exhaustive enums. </div></div></blockquote></div></blockquote><div><br></div><div>This is why I was suggesting another pattern that only captures known cases at compile time:</div><div><br></div><div><div>switch excuse {</div><div> case .eatenByPet :</div><div> //…</div><div><div> case * : // All cases captured at compile time. </div><div> // …</div></div><div> unknown case:</div><div> // …</div><div> }</div></div></div></div><div style="word-wrap:break-word"><div></div></div></blockquote><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Sorry, I don’t understand. However you spell it, what is your use case for this? The stated purpose of “unknown case” is to gain compile-time exhaustiveness testing, but this would not allow for that.</div></div></blockquote><div><br></div><br></div><div><br></div><div><br></div></div><div style="word-wrap:break-word"><div><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;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;color:rgb(36,41,46);font-variant-ligatures:normal"><span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">switch</span> (excuse, notifiedTeacherBeforeDeadline) {
<span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">case</span> (.<span class="m_-8595388434919151480pl-smi" style="box-sizing:border-box">eatenByPet</span>, <span class="m_-8595388434919151480pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">true</span>)<span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span>
<span class="m_-8595388434919151480pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"><span class="m_-8595388434919151480pl-c" style="box-sizing:border-box">//</span> …</span>
<span class="m_-8595388434919151480pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span><span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">case</span> (.<span class="m_-8595388434919151480pl-smi" style="box-sizing:border-box">thoughtItWasDueNextWeek</span>, <span class="m_-8595388434919151480pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">true</span>)<span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span>
<span class="m_-8595388434919151480pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"><span class="m_-8595388434919151480pl-c" style="box-sizing:border-box">//</span> …</span>
<span class="m_-8595388434919151480pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span><span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">case</span> (unknown <span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">case</span>, <span class="m_-8595388434919151480pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">true</span>)<span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span>
<span class="m_-8595388434919151480pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"><span class="m_-8595388434919151480pl-c" style="box-sizing:border-box">//</span> …</span>
<span class="m_-8595388434919151480pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span><span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">case</span> (<span class="m_-8595388434919151480pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">_</span>, <span class="m_-8595388434919151480pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">false</span>)<span class="m_-8595388434919151480pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">:</span>
<span class="m_-8595388434919151480pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"><span class="m_-8595388434919151480pl-c" style="box-sizing:border-box">//</span> …</span>
<span class="m_-8595388434919151480pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>}</pre><div><br></div><div>Im referring to the future direction section in the <a href="https://github.com/jrose-apple/swift-evolution/blob/6061c01fb4a6d742ba7213f46979c9b82891fc14/proposals/0192-non-exhaustive-enums.md#future-directions" target="_blank">new PR</a>. The above example if from there. </div><div><br></div><div>I am fine with `unknown case` being required to be at the end of the switch for now. </div><div><br></div><div>I think of `unknown case` as a pattern that only matches unknown cases no matter where on the switch it is.</div><div><br></div><div>This is why I do not think that `default unknown` would work well once `unknown case` can be used a pattern.</div><div><br></div><div>We can start a new thread on this if you’d like. </div><div></div></div></div></blockquote><div dir="auto"><br></div><div dir="auto">The reason I put forward “default unknown” is precisely because the proposed feature *cannot* be used in a pattern and therefore seems more apt as not a case.</div><div dir="auto"><br></div><div dir="auto">It actually makes it more natural to use in the given example above because “default unknown” could actually be used to provide compile-time exhaustiveness checking for such a tuple pattern, whereas without being able to use “unknown case” in a pattern you can’t write “case (unknown case, _)”.</div><div dir="auto"><br></div><div dir="auto">You still haven’t answered my question, though—what’s the use case for the feature you propose?</div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div> </div></div></div><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div dir="auto" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><blockquote class="gmail_quote" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><br><blockquote type="cite"><div><blockquote class="gmail_quote" style="font-family:Helvetica;font-size:13px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><br></div><div><br></div><blockquote type="cite"><div><div><br></div><div>I'll add these points to the "Alternatives Considered" section in the PR later today.</div><div><br></div><div>Jordan<br><div><br><div><div><br><blockquote type="cite"><div>On Jan 3, 2018, at 22:56, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>> wrote:</div><br class="m_-8595388434919151480m_-6520709161405088222m_-3214780750878788621Apple-interchange-newline"><div>As has already been said, “case unknown” is source-breaking because it conflicts with any real cases named “unknown”; “\unknown” looks like a key path but isn’t, and I wonder if it would potentially conflict with existing key paths.<br><br>In any case, my point was not to bikeshed the “unknown” part, but to ask whether any consideration had been made to have the feature presented as a flavor of default instead of a flavor of case.<br><br><div class="gmail_quote"><div>On Wed, Jan 3, 2018 at 23:57 Cheyo Jimenez <<a href="mailto:cheyo@masters3d.com" target="_blank">cheyo@masters3d.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div></div><div><br></div><div><br>On Jan 3, 2018, at 6:52 PM, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><div>This is a very nice revision. One bikeshedding thought:<div><br></div><div>Since "unknown case" is presented as a special kind of "default", can't be mixed with "default", and can't be used in case patterns, why not "default unknown" (or "unknown default") instead of "unknown case"?</div></div></div></blockquote><div><br></div></div><div dir="auto">`case _ :` is already a special case of default. <div>I’d rather have `case unknown :`</div><div>`unknown case :` is weird because of the order of `case`. </div><div><br></div><div>Another alternative is `case \unknown :`</div><div>`\unknown` would also allow pattern matching. </div></div><div dir="auto"><div><br></div><div><br></div><div><br></div><div><blockquote type="cite"><div><div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 3, 2018 at 8:05 PM, Jordan Rose via swift-evolution<span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span><span><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span><span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><span><div><blockquote type="cite"><div>On Jan 2, 2018, at 18:07, Jordan Rose <<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>> wrote:</div><br class="m_-8595388434919151480m_-6520709161405088222m_-3214780750878788621m_3038813019960738014m_4426090214486360640Apple-interchange-newline"><div><div style="word-wrap:break-word"><div>[Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md" style="font-family:Helvetica,arial,sans-serif" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md</a>]</div><div><br></div><div>Whew! Thanks for your feedback, everyone. On the lighter side of feedback—naming things—it seems that most people seem to like '<b>@frozen</b>', and that does in fact have the connotations we want it to have. I like it too.</div><div><br></div><div>More seriously, this discussion has convinced me that it's worth including what the proposal discusses as a<span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span><b>'future' case</b>. The key point that swayed me is that this can produce a<span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span><i>warning</i> when the switch is missing a case rather than an<span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span><i>error,</i> which both provides the necessary compiler feedback to update your code and allows your dependencies to continue compiling when you update to a newer SDK. I know people on both sides won't be 100% satisfied with this, but does it seem like a reasonable compromise?</div><div><br></div><div>The next question is how to spell it. I'm leaning towards `unexpected case:`, which (a) is backwards-compatible, and (b) also handles "private cases", either the fake kind that you can do in C (as described in the proposal), or some real feature we might add to Swift some day. `unknown case:` isn't bad either.</div><div><br></div><div>I too would like to just do `unknown:` or `unexpected:` but that's technically a source-breaking change:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>switch foo {</div><div>case bar:</div><div> <span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>unknown:</div><div> <span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>while baz() {</div><div> <span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>while garply() {</div><div> <span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>if quux() {</div><div> <span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>break unknown</div><div> <span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>}</div><div> <span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>}</div><div> <span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span>}</div><div>}</div></blockquote><div><br></div><div>Another downside of the `unexpected case:` spelling is that it doesn't work as part of a larger pattern. I don't have a good answer for that one, but perhaps it's acceptable for now.</div><div><br></div><div>I'll write up a revision of the proposal soon and make sure the core team gets my recommendation when they discuss the results of the review.</div><div><br></div><div>---</div><div><br></div><div><div>I'll respond to a few of the more intricate discussions tomorrow, including the syntax of putting a new declaration inside the enum rather than outside. Thank you again, everyone, and happy new year!</div></div></div></div></blockquote><br></div></span><div>I ended up doing these in the opposite order, writing up the new proposal first and not yet responding to the discussion that's further out. You can read my revisions at<span class="m_-8595388434919151480m_-6520709161405088222Apple-converted-space"> </span><a href="https://github.com/apple/swift-evolution/pull/777" target="_blank">https://github.com/apple/swift-evolution/pull/777</a>.</div><div><br></div><div>In particular, I want to at least address:</div><div>- Dave D and Drew C's points about versioned libraries / linking semantics of modules.</div><div>- Jason M's point about migration</div>and I'll do one more pass over the thread to see if there's anything else I didn't address directly. (That doesn't mean everyone who disagrees, just messages where I think there's more I can do to explain why the proposal is the way it is.)<div><br></div><div>Jordan</div><div><br></div><div>P.S. Enjoying the Disney references. Thanks, Nevin and Dave. :-)</div></div><br>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br><br></blockquote></div><br></div></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" 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/mailman/listinfo/swift-evolution</a></span></div></blockquote></div></div></blockquote></div></div></blockquote></div></div></div></div></div></blockquote></div></blockquote></div></blockquote></div></div></blockquote></div></blockquote></div><br></div></blockquote></div></div>