<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 26, 2016, at 10:13 AM, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">Am 26.05.2016 um 16:59 schrieb Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline">On May 26, 2016, at 9:52 AM, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">Am 26.05.2016 um 15:40 schrieb Matthew Johnson &lt;<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class=""><div class=""><br class=""><br class="">Sent from my iPad</div><div class=""><br class="">On May 26, 2016, at 8:25 AM, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">Ceylon requires checks whether cases are disjoint, i.e. when one case contains a superclass of another case then this will be a type error „cases are not disjoint“.<div class=""><br class=""></div><div class="">FWIW: Ceylon requires classes with enumerated subclasses to be abstract.&nbsp;<br class=""></div></div></blockquote><div class=""><br class=""></div>Interesting, thanks for mentioning this. &nbsp;The abstract requirement is what makes disjointedness at least partly possible (what if a subclass has further descendants though?). &nbsp;But it still only works for a single level of inheritance:<div class=""><br class=""></div><div class="">sealed abstract class A {}</div><div class="">class B : A {}</div><div class="">class C : A {}</div><div class="">class D : B {}</div><div class=""><span class="" style="background-color: rgba(255, 255, 255, 0);">class E : B {}</span></div><div class=""><br class=""></div><div class="">With a disjoint requirement I cannot ever match D and E because that would not be exhaustive and I am prohibited from matching them along side B which would be exhaustive but isn't disjoint.</div></div></div></blockquote><div class=""><br class=""></div>Why?</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">switch a {</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">case C: …</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">case D: …</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">case E: …</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">}</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">is exhaustive because B has to be sealed as well (I would require this to be declared explicitly).</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Abstractness seems not to be necessary for that IMO.</div></div></blockquote><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Either you match against B *or* against all its subclasses.</div></div></blockquote><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">In my example `B` is not abstract. &nbsp;`a` might have dynamic type of `B` which would not match any of those cases. &nbsp;</div></div></blockquote><div class=""><br class=""></div>Ah, now I realize why the requirement for abstractness makes sense. Of course. Thanks for pointing that out!</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><div class=""></div></blockquote><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">You didn’t mention that you have to make all non-leaf classes `abstract` (or at least I didn’t understand that from what you wrote). &nbsp;</div></div></blockquote><div class=""><br class=""></div>The requirement in Ceylon is for classes with enumerated subclasses. B would have to declare D and E as enumerated subclasses (like I did for Child2 in the Ceylon example). In Ceylon this is not required, B could have normal subclasses D and E, but then you could not match against D or E at all because these would not be exhaustive (B might have other subclasses). The problem therefore is not stemming from disjointness requirements.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">As soon as D and E are declared as disjoint (i.e. if B would be declared `sealed`) matching against them would be possible but B would have to be abstract.</div></div></blockquote><div><br class=""></div><div>In my example B is implicitly sealed because it has a sealed ancestor. &nbsp;If it weren’t you would be able to violate the sealed property of the ancestor by inheriting from B.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">If I remove the enumerated subclasses from Child2 in the example I am allowed to make Child2 non-abstract. This of course results in the type error that the cases Child1 | Grandchild1 | Grandchild2 are not covering Parent anymore and I have to change the cases to match Child1 | Child2, removing the grandchildren matches because they are not disjoint with Child2.</div></div></blockquote><div><br class=""></div><div>Got it. &nbsp;The enumerated subclasses are “partial sealing”. &nbsp;They seal one level of one branch of the inheritance hierarchy. &nbsp;Interesting. &nbsp;You can get exhaustive matching without needing to seal the entire hierarchy. &nbsp;I’m not sure if I like this or not. &nbsp;It is something to consider though, and it is more flexible.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""><div class=""><br class=""></div><blockquote type="cite" class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I don’t like a design that requires non-leaf classes to be abstract. &nbsp;First, it would require introducing abstract classes into Swift, which is a totally separate conversation and something I am not convinced is a good idea. &nbsp;</div></blockquote><div class=""><br class=""></div><div class="">Well, I think abstract classes are something that is sorely missing in Swift! Very sorely missing…</div></div></div></blockquote><div><br class=""></div><div>I’ll keep my mind open about it. &nbsp;My concern is that people will gravitate to the familiar where protocols would be a better design. &nbsp;I haven’t yet missed abstract classes in Swift.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">But as you say that is a separate conversation and an easy fix would be to restrict `sealed` to protocols first.</div></div></div></blockquote><div><br class=""></div><div>Why do that? &nbsp;We can have exhaustive switches without requiring abstract.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">But it is also overly restrictive. &nbsp;There are valid cases where you might want an exhaustive switch for a sealed hierarchy that has concrete parent classes.</div></div></blockquote><div class=""><br class=""></div><div class="">In that case your suggestion of `isExactly` (or something shorter :-) would indeed be the solution.</div></div></div></blockquote><div><br class=""></div><div>Yep. &nbsp;Any ideas for something more concise?</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div><div class="">-Thorsten</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">If you want all non-leaf types to be abstract you should probably consider using protocols in Swift. &nbsp;</div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Example in Ceylon:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><pre class="" style="background-color: rgb(255, 255, 255); font-family: Menlo;"><pre class="" style="font-family: Menlo;"><pre class="" style="font-family: Menlo;"><span class="" style="color: rgb(51, 153, 204);">abstract </span><span class="" style="color: rgb(76, 76, 76);">class </span><span class="" style="color: rgb(153, 0, 102);">Parent</span>() <span class="" style="color: rgb(76, 76, 76);">of </span><span class="" style="color: rgb(153, 0, 102);">Child1 </span>| <span class="" style="color: rgb(153, 0, 102);">Child2 </span>{}<br class=""><br class=""><span class="" style="color: rgb(76, 76, 76);">class </span><span class="" style="color: rgb(153, 0, 102);">Child1</span>() <span class="" style="color: rgb(76, 76, 76);">extends </span><span class="" style="color: rgb(153, 0, 102);">Parent</span>() {}<br class=""><br class=""><span class="" style="color: rgb(51, 153, 204);">abstract </span><span class="" style="color: rgb(76, 76, 76);">class </span><span class="" style="color: rgb(153, 0, 102);">Child2</span>() <span class="" style="color: rgb(76, 76, 76);">of </span><span class="" style="color: rgb(153, 0, 102);">Grandchild1 </span>| <span class="" style="color: rgb(153, 0, 102);">Grandchild2 </span><span class="" style="color: rgb(76, 76, 76);">extends </span><span class="" style="color: rgb(153, 0, 102);">Parent</span>() {}<br class=""><br class=""><span class="" style="color: rgb(76, 76, 76);">class </span><span class="" style="color: rgb(153, 0, 102);">Grandchild1</span>() <span class="" style="color: rgb(76, 76, 76);">extends </span><span class="" style="color: rgb(153, 0, 102);">Child2</span>() {}<br class=""><br class=""><span class="" style="color: rgb(76, 76, 76);">class </span><span class="" style="color: rgb(153, 0, 102);">Grandchild2</span>() <span class="" style="color: rgb(76, 76, 76);">extends </span><span class="" style="color: rgb(153, 0, 102);">Child2</span>() {}<br class=""><br class=""><span class="" style="color: rgb(76, 76, 76);">void </span><span class="" style="color: rgb(0, 51, 153);">main</span>() {<br class="">    <span class="" style="color: rgb(153, 0, 102);">Parent </span><span class="" style="color: rgb(0, 51, 153);">foo </span>= <span class="" style="color: rgb(153, 0, 102);">Child1</span>();<br class=""><br class="">    <span class="" style="color: rgb(76, 76, 76);">switch </span>(<span class="" style="color: rgb(0, 51, 153);">foo</span>)<br class="">    <span class="" style="color: rgb(76, 76, 76);">case </span>(<span class="" style="color: rgb(76, 76, 76);">is </span><span class="" style="color: rgb(153, 0, 102);">Child1</span>) {<br class="">        <span class="" style="color: rgb(0, 51, 153);">print</span>(<span class="" style="color: rgb(0, 0, 255);">"Child1"</span>);<br class="">    }<br class="">    <span class="" style="color: rgb(76, 76, 76);">case </span>(<span class="" style="color: rgb(76, 76, 76);">is </span><span class="" style="color: rgb(153, 0, 102);">Grandchild1</span>) {<br class="">        <span class="" style="color: rgb(0, 51, 153);">print</span>(<span class="" style="color: rgb(0, 0, 255);">"Grandchild1"</span>);<br class="">    }<br class="">    <span class="" style="color: rgb(76, 76, 76);">case </span>(<span class="" style="color: rgb(76, 76, 76);">is </span><span class="" style="color: rgb(153, 0, 102);">Grandchild2</span>) {<br class="">        <span class="" style="color: rgb(0, 51, 153);">print</span>(<span class="" style="color: rgb(0, 0, 255);">"Grandchild2"</span>);<br class="">    }<br class="">}</pre><pre class="" style="font-family: Menlo;"><br class=""></pre></pre></pre></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">-Thorsten</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">&nbsp;<br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">I don't think that solution is appropriate to Swift. &nbsp;</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">-Thorsten</div><div class=""><br class=""></div><div class="">&nbsp;<br class=""><div class=""><blockquote type="cite" class=""><div class="">Am 25.05.2016 um 19:49 schrieb Matthew Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class=""><div class=""><br class=""><br class="">Sent from my iPad</div><div class=""><br class="">On May 25, 2016, at 12:41 PM, Charlie Monroe &lt;<a href="mailto:charlie@charliemonroe.net" class="">charlie@charliemonroe.net</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class=""><div dir="auto" class=""><div class="">Got it. &nbsp;You could also say it is safer because you can't have a supertype case "swallow" a subtype value accidentally. &nbsp;An "exact type" cast would prevent this possibility.</div></div></blockquote><div class=""><br class=""></div><div class="">This still can be an issue since you still need to do the switch in init(instance:), but it's just one place within the entire module, so it can be more easily managed...</div></div></div></blockquote><div class=""><br class=""></div>Yes, agree. &nbsp;That's why your enum is safer. &nbsp;I think we do need an exact type cast to prevent this problem. &nbsp;'isExaclty' and 'asExactly' seem are a bit verbose but are very clear. &nbsp;I can't think of anything I like that is more concise.<div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""><blockquote type="cite" class=""><div dir="auto" class=""><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">enum AnimalSubclasses {</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>case Dog</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>case Cat</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>init(instance: Animal) {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>switch instance {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>case is Dog: self = .Dog</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>case is Cat: self = .Cat</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>default: fatalError("Unhandled instance \(instance)!")</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div class=""><br class=""></div><div class="">}</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 10px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">One thing I have considered that might also be worth introducing is an exact match cast. &nbsp;This would prevent the possibility of putting a superclass case first and having it “steal” subclasses which were intended to be covered by a case later in the switch. &nbsp;If we introduce exact match you would be able to write a switch that must always cover every concrete type, including all subclasses. &nbsp;</div><br class="" style="font-family: Helvetica; font-size: 10px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 10px; font-style: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><br class=""></div><div class="">Charlie</div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On May 25, 2016, at 4:41 AM, Leonardo Pessoa via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class=""><div class=""><div class="" style="font-family: Calibri, sans-serif; font-size: 11pt;">Limiting the amount of subclasses is not really a good idea as you would need to introduce another mechanism in the language while the proposed feature requires much less. And you're thinking only about the restrictive set (internal and private) and forgetting the more open end (public). Why is it so bad for this proposal to support requiring the default case? If its possible for the compiler to discover you covered all possible cases it would be fine not having default but IMHO in most cases it will find out there are more not explicitly covered.<br class=""></div></div><div dir="ltr" class=""><hr class=""><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt; font-weight: bold;">From:<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt;"><a href="mailto:davesweeris@mac.com" class="">David Sweeris</a></span><br class=""><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt; font-weight: bold;">Sent:<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt;">‎24/‎05/‎2016 11:01 PM</span><br class=""><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt; font-weight: bold;">To:<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt;"><a href="mailto:austinzheng@gmail.com" class="">Austin Zheng</a></span><br class=""><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt; font-weight: bold;">Cc:<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt;"><a href="mailto:me@lmpessoa.com" class="">Leonardo Pessoa</a>;<span class="Apple-converted-space">&nbsp;</span><a href="mailto:swift-evolution@swift.org" class="">swift-evolution</a></span><br class=""><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt; font-weight: bold;">Subject:<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-family: Calibri, sans-serif; font-size: 11pt;">Re: [swift-evolution] [Pitch] Exhaustive pattern matching forprotocols and classes</span><br class=""><br class=""></div><div class="">Or if there was a way to declare that a class/protocol can only have a defined set of subclasses/conforming types.<br class=""><br class="">Sent from my iPhone</div><div class=""><br class="">On May 24, 2016, at 15:35, Austin Zheng via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">If you pattern match on a type that is declared internal or private, it is impossible for the compiler to not have an exhaustive list of subclasses that it can check against.<div class=""><br class=""></div><div class="">Austin</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, May 24, 2016 at 1:29 PM, Leonardo Pessoa<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:me@lmpessoa.com" target="_blank" class="">me@lmpessoa.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">I like this but I think it would be a lot hard to ensure you have all<br class="">subclasses covered. Think of frameworks that could provide many<br class="">unsealed classes. You could also have an object that would have to<br class="">handle a large subtree (NSObject?) and the order in which the cases<br class="">are evaluated would matter just as in exception handling in languages<br class="">such as Java (or require some evaluation from the compiler to raise<br class="">warnings). I'm +1 for this but these should be open-ended like strings<br class="">and require the default case.<br class=""><br class="">On 24 May 2016 at 17:08, Austin Zheng via swift-evolution<br class=""><div class="HOEnZb"><div class="h5">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">&gt; I have been hoping for the exhaustive pattern matching feature for a while<br class="">&gt; now, and would love to see a proposal.<br class="">&gt;<br class="">&gt; Austin<br class="">&gt;<br class="">&gt; On Tue, May 24, 2016 at 1:01 PM, Matthew Johnson via swift-evolution<br class="">&gt; &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">&gt;&gt;<br class="">&gt;&gt; Swift currently requires a default pattern matching clause when you switch<br class="">&gt;&gt; on an existential or a non-final class even if the protocol or class is<br class="">&gt;&gt; non-public and all cases are covered.&nbsp; It would be really nice if the<br class="">&gt;&gt; default clause were not necessary in this case.&nbsp; The compiler has the<br class="">&gt;&gt; necessary information to prove exhaustiveness.<br class="">&gt;&gt;<br class="">&gt;&gt; Related to this is the idea of introducing something like a `sealed`<br class="">&gt;&gt; modifier that could be applied to public protocols and classes.&nbsp; The<br class="">&gt;&gt; protocol or class would be visible when the module is imported, but<br class="">&gt;&gt; conformances or subclasses outside the declaring module would be prohibited.<br class="">&gt;&gt; Internal and private protocols and classes would implicitly be sealed since<br class="">&gt;&gt; they are not visible outside the module.&nbsp; Any protocols that inherit from a<br class="">&gt;&gt; sealed protocol or classes that inherit from a sealed class would also be<br class="">&gt;&gt; implicitly sealed (if we didn’t do this the sealing of the superprotocol /<br class="">&gt;&gt; superclass could be violated by conforming to or inheriting from a<br class="">&gt;&gt; subprotocol / subclass).<br class="">&gt;&gt;<br class="">&gt;&gt; Here are examples that I would like to see be valid:<br class="">&gt;&gt;<br class="">&gt;&gt; protocol P {}<br class="">&gt;&gt; // alternatively public sealed protocol P {}<br class="">&gt;&gt; struct P1: P {}<br class="">&gt;&gt; struct P2: P {}<br class="">&gt;&gt;<br class="">&gt;&gt; func p(p: P) -&gt; Int {<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;switch p {<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;case is P1: return 1 // alternatively an `as` cast<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;case is P2: return 2 // alternatively an `as` cast<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;}<br class="">&gt;&gt; }<br class="">&gt;&gt;<br class="">&gt;&gt; class C {}<br class="">&gt;&gt; // alternatively public sealed class C {}<br class="">&gt;&gt; class C1: C {}<br class="">&gt;&gt; class C2: C {}<br class="">&gt;&gt;<br class="">&gt;&gt; func c(c: C) -&gt; Int {<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;switch c {<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;case is C1: return 1 // alternatively an `as` cast<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;case is C2: return 2 // alternatively an `as` cast<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;case is C: return 0&nbsp; &nbsp;// alternatively an `as` cast<br class="">&gt;&gt;&nbsp; &nbsp; &nbsp;}<br class="">&gt;&gt; }<br class="">&gt;&gt;<br class="">&gt;&gt; I am wondering if this is something the community is interested in.&nbsp; If<br class="">&gt;&gt; so, I am wondering if this is something that might be possible in the Swift<br class="">&gt;&gt; 3 timeframe (maybe just for private and internal protocols and classes) or<br class="">&gt;&gt; if it should wait for Swift 4 (this is likely the case).<br class="">&gt;&gt;<br class="">&gt;&gt; -Matthew<br class="">&gt;&gt; _______________________________________________<br class="">&gt;&gt; swift-evolution mailing list<br class="">&gt;&gt;<span class="Apple-converted-space">&nbsp;</span><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">&gt;&gt;<span class="Apple-converted-space">&nbsp;</span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" rel="noreferrer" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">&gt;<br class="">&gt;<br class="">&gt;<br class="">&gt; _______________________________________________<br class="">&gt; swift-evolution mailing list<br class="">&gt;<span class="Apple-converted-space">&nbsp;</span><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">&gt;<span class="Apple-converted-space">&nbsp;</span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" rel="noreferrer" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">&gt;<br class=""></div></div></blockquote></div><br class=""></div></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></blockquote></div><br class=""></div></blockquote></div></div></blockquote></div><br class=""></div></blockquote></div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></div></div></div></blockquote></div></div></div></div></div></blockquote></div></div></blockquote></div></blockquote></div></div></blockquote></div><br class=""></body></html>