<div dir="ltr">Paul,<div><br></div><div>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><br></div><div>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><br></div><div>Dan</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jun 30, 2016 at 1:42 PM Paul Cantrell &lt;<a href="mailto:cantrell@pobox.com">cantrell@pobox.com</a>&gt; 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"><div>While it doesn’t give all the “raw value” functionality of enum, it’s possible to use object instance uniqueness to get enum-like behavior that can be extended:</div><div><br></div><div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>    </span><span style="color:#323e7d">public</span><span> </span><span style="color:#323e7d">protocol</span><span> OpenEnum: </span><span style="color:#323e7d">class</span><span>, </span><span style="color:#587ea8">Hashable</span><span> { }</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;color:rgb(50,62,125)"><span style="color:#000000">    </span><span>extension</span><span style="color:#000000"> </span><span style="color:#587ea8">OpenEnum</span><span style="color:#000000"> {</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>      </span><span style="color:#323e7d">public</span><span> </span><span style="color:#323e7d">var</span><span> hashValue: </span><span style="color:#587ea8">Int</span><span> {</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;color:rgb(88,126,168)"><span style="color:#000000">        </span><span style="color:#323e7d">return</span><span style="color:#000000"> </span><span>ObjectIdentifier</span><span style="color:#000000">(</span><span style="color:#323e7d">self</span><span style="color:#000000">).</span><span>hashValue</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>      }</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>    }</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>    </span><span style="color:#323e7d">public</span><span> </span><span style="color:#323e7d">func</span><span> ==&lt;T: </span><span style="color:#587ea8">OpenEnum</span><span>&gt;(lhs: </span><span style="color:#587ea8">T</span><span>, rhs: </span><span style="color:#587ea8">T</span><span>) -&gt; </span><span style="color:#587ea8">Bool</span><span> {</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>      </span><span style="color:#323e7d">return</span><span> lhs === rhs</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>    }</span></div></div><div><span><br></span></div><div><span>A library can provide:</span></div><div><span><br></span></div><div><span><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;color:rgb(88,126,168)"><span style="color:#000000">    </span><span style="color:#323e7d">public</span><span style="color:#000000"> </span><span style="color:#323e7d">final</span><span style="color:#000000"> </span><span style="color:#323e7d">class</span><span style="color:#000000"> Color: </span><span>OpenEnum</span><span style="color:#000000">, </span><span>CustomStringConvertible</span><span style="color:#000000"> {</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>      </span><span style="color:#323e7d">public</span><span> </span><span style="color:#323e7d">let</span><span> description: </span><span style="color:#587ea8">String</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>      </span><span style="color:#323e7d">public</span><span> </span><span style="color:#323e7d">init</span><span>(description: </span><span style="color:#587ea8">String</span><span>) {</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>        </span><span style="color:#323e7d">self</span><span>.</span><span style="color:#587ea8">description</span><span> = description</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>      }</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;color:rgb(50,62,125)"><span style="color:#000000">      </span><span>static</span><span style="color:#000000"> </span><span>let</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>        black = </span><span style="color:#587ea8">Color</span><span>(description: </span><span style="color:#843e64">&quot;black&quot;</span><span>),</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>        white = </span><span style="color:#587ea8">Color</span><span>(description: </span><span style="color:#843e64">&quot;white&quot;</span><span>)</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>    }</span></div><div><span><br></span></div><div><span>And then in a client project:</span></div><div><span><br></span></div><div><span><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;color:rgb(50,62,125)"><span style="color:#000000">    </span><span>extension</span><span style="color:#000000"> </span><span style="color:#587ea8">Color</span><span style="color:#000000"> {</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo;color:rgb(50,62,125)"><span style="color:#000000">      </span><span>static</span><span style="color:#000000"> </span><span>let</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>        puce = </span><span style="color:#587ea8">Color</span><span>(description: </span><span style="color:#843e64">&quot;puce&quot;</span><span>),</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>        mauve = </span><span style="color:#587ea8">Color</span><span>(description: </span><span style="color:#843e64">&quot;mauve&quot;</span><span>),</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>        fuchsia = </span><span style="color:#587ea8">Color</span><span>(description: </span><span style="color:#843e64">&quot;fuchsia&quot;</span><span>)</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span>    }</span></div><div><span><br></span></div><div>(This is how Siesta provides an extensible set of pipeline stages. <a href="https://github.com/bustoutsolutions/siesta/pull/64" target="_blank">https://github.com/bustoutsolutions/siesta/pull/64</a>)</div><div><span><br></span></div><div><span>With this approach, you still get the .member shortcut in some circumstances:</span></div><div><span><br></span></div><div><span><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><span style="color:#323e7d">    let</span><span> eyebleedPalette: [</span><span style="color:#587ea8">Color</span><span>] = [.fuchsia, .black, .mauve]</span></div></span></div><div><span><br></span></div><div><span>…but not in others:</span></div></span></div></span></div><div><br></div><div><div style="margin:0px;font-size:10.5px;line-height:normal;font-family:Menlo"><div style="margin:0px;font-size:10.5px;line-height:normal;color:rgb(102,139,73)"><span style="color:#000000">    </span><span>// Compiles</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"><span>    </span><span style="color:#323e7d">switch</span><span>(</span><span style="color:#587ea8">color</span><span>) {</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"><span>      </span><span style="color:#323e7d">case</span><span> </span><span style="color:#587ea8"><b>Color</b></span><span>.red: </span><span style="color:#587ea8">print</span><span>(</span><span style="color:#843e64">&quot;Danger!&quot;</span><span>)</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"><span>      </span><span style="color:#323e7d">case</span><span> </span><span style="color:#587ea8"><b>Color</b></span><span>.mauve: </span><span style="color:#587ea8">print</span><span>(</span><span style="color:#843e64">&quot;Dancing!&quot;</span><span>)</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;color:rgb(132,62,100)"><span style="color:#000000">      </span><span style="color:#323e7d">default</span><span style="color:#000000">: </span><span style="color:#587ea8">print</span><span style="color:#000000">(</span><span>&quot;Nothing notable&quot;</span><span style="color:#000000">)</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"><span>    }</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;min-height:12px"><span></span><br></div><div style="margin:0px;font-size:10.5px;line-height:normal;color:rgb(102,139,73)"><span style="color:#000000">    </span><span>// Does not compile</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"><span>    </span><span style="color:#323e7d">switch</span><span>(</span><span style="color:#587ea8">color</span><span>) {</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"><span>      </span><span style="color:#323e7d">case</span><span> .red: </span><span style="color:#587ea8">print</span><span>(</span><span style="color:#843e64">&quot;Danger!&quot;</span><span>)</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"><span>      </span><span style="color:#323e7d">case</span><span> .mauve: </span><span style="color:#587ea8">print</span><span>(</span><span style="color:#843e64">&quot;Dancing!&quot;</span><span>)</span></div><div style="margin:0px;font-size:10.5px;line-height:normal;color:rgb(132,62,100)"><span style="color:#000000">      </span><span style="color:#323e7d">default</span><span style="color:#000000">: </span><span style="color:#587ea8">print</span><span style="color:#000000">(</span><span>&quot;Nothing notable&quot;</span><span style="color:#000000">)</span></div><div style="margin:0px;font-size:10.5px;line-height:normal"><span>    }</span></div><div><span><br></span></div></div></div><div>Given that this already comes close to giving the sort of functionality one would want out of an extensible enum, perhaps it’s better to fill out the gaps in this approach instead of adding a new language feature? This would have the advantage of not adding a keyword, and presumably provide useful behaviors that generalize to patterns other than extensible enums.</div><div><br></div><div>Cheers,</div><div><br></div><div>Paul</div></div><div style="word-wrap:break-word"><br><div><blockquote type="cite"><div>On Jun 30, 2016, at 3:23 PM, Guillermo Peralta Scura via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr">I think the approach taken by your proporsal is really good. Would love to have that feature for the language.<div><br><div class="gmail_quote"><div dir="ltr">El jue., 30 jun. 2016 a las 16:19, Edward Valentini via swift-evolution (&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;) escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div></div><div><br></div><div>I really like the idea of making it opt in with the extensible keyword as opposed to opt out with final so this way there is no impact on existing code </div></div><div dir="auto"><div><br>On Jun 30, 2016, at 16:15, Dan Appel &lt;<a href="mailto:dan.appel00@gmail.com" target="_blank">dan.appel00@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">I&#39;ve had a draft of a proposal lying around for a while which addresses exactly this, but I haven&#39;t gotten around to sending it out for comments yet. <a href="https://gist.github.com/Danappelxx/41b7c2e86787f75698bd48135cc616f5" target="_blank">Link</a>.<div><br></div><div>Would appreciate if you guys took a look.</div><div>Dan Appel<br></div><div><br><div>Pasted inline below<br><div><br></div><div><h1 style="font-size:2.25em;margin:0px 0px 16px;line-height:1.2;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;">Extensible Enums</h1><ul style="padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px"><li>Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-name.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank">SE-NNNN</a></li><li>Author: <a href="https://github.com/danappelxx" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank">Dan Appel</a></li><li>Status: <span><a href="https://gist.github.com/Danappelxx/41b7c2e86787f75698bd48135cc616f5#rationale" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank">Awaiting review</a></span></li><li>Review manager: TBD</li></ul><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;"><a href="https://gist.github.com/Danappelxx/41b7c2e86787f75698bd48135cc616f5#introduction" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"></a>Introduction</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">This proposal introduces a new keyword that can be applied to enums which allows new cases to be introduced in extensions.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">Swift-evolution thread: <a href="https://lists.swift.org/pipermail/swift-evolution" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank">[RFC] Extensible Enums</a></p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;"><a href="https://gist.github.com/Danappelxx/41b7c2e86787f75698bd48135cc616f5#motivation" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"></a>Motivation</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">Enums are a powerful feature which provides a lot of benefit if you have a limited number of behaviors. For example, associated values provide the ability to make every case essentially a separate type. However, due to the static nature of enums, they cannot be used in situations where they would otherwise be a perfect fit. </p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">An example of this would be the use of an Error enum like so:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px"><pre style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span style="color:rgb(167,29,93)">enum</span> FileError: ErrorProtocol {
    <span style="color:rgb(167,29,93)">case</span> fileNotFound(path: <span style="color:rgb(0,134,179)">String</span>)
    <span style="color:rgb(167,29,93)">case</span> corruptedFile(bytes: [<span style="color:rgb(0,134,179)">Int8</span>])
}
<span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">readFile</span>() throws { <span style="color:rgb(167,29,93)">...</span> }

<span style="color:rgb(150,152,150)">// elsewhere in the codebase</span>
<span style="color:rgb(167,29,93)">do</span> {
    <span style="color:rgb(167,29,93)">try</span> readFile()
} <span style="color:rgb(167,29,93)">catch</span> <span style="color:rgb(167,29,93)">let</span> error <span style="color:rgb(167,29,93)">as</span> FileError {
    <span style="color:rgb(167,29,93)">switch</span> error {
        <span style="color:rgb(167,29,93)">case</span> <span style="color:rgb(167,29,93)">.</span>fileNotFound(<span style="color:rgb(167,29,93)">let</span> path): <span style="color:rgb(150,152,150)">// handle error</span>
        <span style="color:rgb(167,29,93)">case</span> <span style="color:rgb(167,29,93)">.</span>corruptedFile(<span style="color:rgb(167,29,93)">let</span> bytes): <span style="color:rgb(150,152,150)">// handle error</span>
    }
} <span style="color:rgb(167,29,93)">catch</span> { <span style="color:rgb(167,29,93)">...</span> }</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">While this is generally a good approach, it can be very dangerous for library consumers if the author exposes the error to the user. This is due to the fact that the <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">switch</code> statement has to be exhaustive and is only satisfied when all enum cases have been accounted for. What this means for library authors is that every time they add a new case to a public enum, they are breaking the exhaustivity of the <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">switch</code> and making their library backwards-incompatible.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">Currently, the best workaround is to use a <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">struct</code> with static instances and overloading the <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">~=</code> operator. This allows for similar <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">switch</code> behavior but overall is much less flexible, missing key features such as associated values.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">Another example is when the library is split into multiple modules, where the error is defined in the first module and the second module wants to add some error cases. An enum is very rarely used in this case because you cannot add cases in other modules. Instead, library authors either use an error protocol, and add more types that conform to it, or use the struct approach shown above. While this is not terrible, adding cases in extensions would better translate the intention of the author and adds more flexiblity.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;"><a href="https://gist.github.com/Danappelxx/41b7c2e86787f75698bd48135cc616f5#proposed-solution" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"></a>Proposed solution</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">The solution proposed is quite simple: add an <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">extensible</code> keyword/modifier that can be applied to enums, which would require the <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">default</code> case when switched on and allow new cases to be added in extensions.</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">Here is the translation of the very first example to the use an <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">extensible</code> enum instead, with a new case added:</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px"><pre style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal">extensible <span style="color:rgb(167,29,93)">enum</span> ThingError: ErrorProtocol {
    <span style="color:rgb(167,29,93)">case</span> fileNotFound(path: <span style="color:rgb(0,134,179)">String</span>)
    <span style="color:rgb(167,29,93)">case</span> corruptedFile(bytes: [<span style="color:rgb(0,134,179)">Int8</span>])
    <span style="color:rgb(167,29,93)">case</span> failedReadingFile
}
<span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">readFile</span>() throws { <span style="color:rgb(167,29,93)">...</span> }

<span style="color:rgb(150,152,150)">// elsewhere in the codebase</span>
<span style="color:rgb(167,29,93)">do</span> {
    <span style="color:rgb(167,29,93)">try</span> readFile()
} <span style="color:rgb(167,29,93)">catch</span> <span style="color:rgb(167,29,93)">let</span> error <span style="color:rgb(167,29,93)">as</span> ThingError {
    <span style="color:rgb(167,29,93)">switch</span> error {
        <span style="color:rgb(167,29,93)">case</span> <span style="color:rgb(167,29,93)">.</span>fileNotFound(<span style="color:rgb(167,29,93)">let</span> path): <span style="color:rgb(150,152,150)">// handle error</span>
        <span style="color:rgb(167,29,93)">case</span> <span style="color:rgb(167,29,93)">.</span>corruptedFile(<span style="color:rgb(167,29,93)">let</span> bytes): <span style="color:rgb(150,152,150)">// handle error</span>
        <span style="color:rgb(167,29,93)">default</span>: <span style="color:rgb(150,152,150)">// handle future errors that don&#39;t exist yet</span>
    }
} <span style="color:rgb(167,29,93)">catch</span> { <span style="color:rgb(167,29,93)">...</span> }</pre></div><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">For the second example, we can simply extend the enum in the higher-level module.</p><div style="margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px"><pre style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal"><span style="color:rgb(150,152,150)">// Module FileProtocol</span>

extensible <span style="color:rgb(167,29,93)">enum</span> FileError: ErrorProtocol {
    <span style="color:rgb(167,29,93)">case</span> fileNotFound(path: <span style="color:rgb(0,134,179)">String</span>)
}

<span style="color:rgb(167,29,93)">protocol</span> FileProtocol {
    <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">read</span>() throws
}

<span style="color:rgb(150,152,150)">// Module File</span>

<span style="color:rgb(167,29,93)">extension</span> FileError {
    <span style="color:rgb(167,29,93)">case</span> corruptedFile(bytes: [<span style="color:rgb(0,134,179)">Int8</span>])
    <span style="color:rgb(167,29,93)">case</span> failedReadingFile
}

<span style="color:rgb(167,29,93)">struct</span> File: FileProtocol {
    <span style="color:rgb(167,29,93)">func</span> <span style="color:rgb(121,93,163)">read</span>() throws { <span style="color:rgb(167,29,93)">...</span> }
}</pre></div><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;"><a href="https://gist.github.com/Danappelxx/41b7c2e86787f75698bd48135cc616f5#detailed-design" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"></a>Detailed design</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">A new keyword would be added to the language which is only allowed in front of the <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">enum</code> keyword. When an enum is marked <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">extensible</code>, new cases can be added in extensions and switches that are performed on it require a <code style="font-family:consolas,&#39;liberation mono&#39;,menlo,courier,monospace;font-size:14px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">default</code>case.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;"><a href="https://gist.github.com/Danappelxx/41b7c2e86787f75698bd48135cc616f5#impact-on-existing-code" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"></a>Impact on existing code</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">There is no impact on existing code since this is purely an additive feature.</p><h2 style="margin-top:1em;margin-bottom:16px;line-height:1.225;font-size:1.75em;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;"><a href="https://gist.github.com/Danappelxx/41b7c2e86787f75698bd48135cc616f5#alternatives-considered" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1" target="_blank"></a>Alternatives considered</h2><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px">No alternatives have been considered (yet).</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:&#39;helvetica neue&#39;,helvetica,&#39;segoe ui&#39;,arial,freesans,sans-serif,&#39;apple color emoji&#39;,&#39;segoe ui emoji&#39;,&#39;segoe ui symbol&#39;;font-size:16px"><br></p></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jun 30, 2016 at 1:04 PM David Sweeris via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">By itself, this would break switch statements, since they have to be exhaustive.<br>
<br>
If anyone has any ideas about how to fix that, I&#39;m all ears.<br>
<br>
- Dave Sweeris<br>
<br>
&gt; On Jun 30, 2016, at 14:58, Edward Valentini via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt; I am finding myself in a situation where the most elegant &quot;swifty&quot; solution would be to allow enum extensions to add to existing case options.  For example lets say I&#39;m using a library that has the following enum defined:<br>
&gt;<br>
&gt; enum MyDirection {<br>
&gt;   case east, west<br>
&gt; }<br>
&gt;<br>
&gt; My app for example also makes use of north and south, so I would love to be able to write:<br>
&gt;<br>
&gt; extension MyDirection {<br>
&gt;   case north,south<br>
&gt; }<br>
&gt;<br>
&gt; In objective c, one would probably have defined constants like MyDirectionEast etc...  these would probably have been mapped to ints or strings so a consumer of this library could have easily extended this to add additional functionality, but using constants like that is not very &quot;swifty&quot;<br>
&gt;<br>
&gt; I&#39;m curious what the swift community thinks.<br>
&gt;<br>
&gt; Thank you<br>
&gt; _______________________________________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
&gt; <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>
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>
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div><div>Dan Appel<br></div></div></div></div>
</div></blockquote></div>_______________________________________________<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>
</blockquote></div></div></div>
_______________________________________________<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" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div><div>Dan Appel<br></div></div></div></div>