<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 Jun 30, 2016, at 3:54 PM, Dan Appel <<a href="mailto:dan.appel00@gmail.com" class="">dan.appel00@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">That is the current workaround (as the proposal mentions), but it is still missing support for enum features such as associated values and the pattern matching power that they bring.</div></div></div></blockquote><div><br class=""></div><div>Fair enough, it would be hard to generalize pattern matching to this approach. Associated types are a whole other kettle of fish.</div><br class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="">Also, by locking your OpenEnum conformers to reference types, you lose out on the value-semantics (very important, even for enums), and bring in the extra weight that a class is.</div></div></blockquote><div><br class=""></div><div>The class approach is the more lightweight option when you aren’t trying to get associated-value-like behavior.</div><div><br class=""></div><div>There’s a fixed pool of instances, one per possible value, so there’s no per-usage allocation overhead. All one passes around are references to those fixed instances, so passing and comparing values is a one-word operation. The class is final, so any method dispatch is static.</div><div><br class=""></div><div>Finally, you get the simplicity of leaning on pointer uniqueness to give you case uniqueness. Nothing to sneeze at there.</div><div><br class=""></div><div>• • •</div><div><br class=""></div><div>If you’re looking to have associated type-like behavior _and_ open cases, then yes, this “unique instances” approach breaks down.</div><div><br class=""></div><div>At that point, though, why not just use a collection of separate struct types implementing a shared protocol?</div><div><br class=""></div><div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">public</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">protocol</span><span style="font-variant-ligatures: no-common-ligatures" class=""> FileError: </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">ErrorProtocol</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { }</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> FileNotFound: </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">FileError</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> path: </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">String</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> CorruptedFile {</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> bytes: [</span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">Int8</span><span style="font-variant-ligatures: no-common-ligatures" class="">]</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; min-height: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> handleFileError(error: </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">FileError</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class="">(error) {</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo; color: rgb(88, 126, 168);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">case</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">is</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">CorruptedFile</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">:</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #843e64" class="">"Bummer"</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> fileNotFound </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">as</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">FileNotFound</span><span style="font-variant-ligatures: no-common-ligatures" class="">:</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #843e64" class="">"Can’t find </span><span style="font-variant-ligatures: no-common-ligatures" class="">\</span><span style="font-variant-ligatures: no-common-ligatures; color: #843e64" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">fileNotFound.</span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">path</span><span style="font-variant-ligatures: no-common-ligatures; color: #843e64" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div>Here the dynamic type takes on the role of the enum value, and <span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(50, 62, 125);" class="">case</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(50, 62, 125);" class="">let</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""> x </span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(50, 62, 125);" class="">as</span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(88, 126, 168);" class="">X</span> gives you must of what associated types give.</div><div><br class=""></div><div>Separate struct types are what I use for the problem the proposal mentions — structured, matchable errors with diagnostic data — and it does work out nicely in practice. Nicer, in fact; I’d say that this:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class=""> if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> error </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">is</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">FileError</span><span style="font-variant-ligatures: no-common-ligatures" class=""> { … }</span></div></div><div><br class=""></div><div>…is easier to read and to remember than this:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class=""> if</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #323e7d" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #587ea8" class="">fileError</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = error { … }</span></div></div><div><br class=""></div><div>Cheers,</div><div><br class=""></div><div>Paul</div><div><br class=""></div></div></body></html>