<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Jan 13, 2017, at 15:10, Anton Zhilin via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">That seems pretty close to Rust’s <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">derive</code>. Why not invent a similar syntax in Swift? Otherwise it will make us look through all the sources to make sure deriving is used.</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">enum Option: @derive Equatable {
    ...
}
</code></pre><p style="margin:0px 0px 1.2em!important">Also, we can get better looking compilation errors, like:</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">ERROR at line 1, col 14: could not derive Equatable for Option
enum Option: @derive Equatable {
             ^~~~~~~~~~~~~~~~~</code></pre></div></div></blockquote><br><div>I think that idea came up once before... can't remember where, though, or what we thought of it at the time.</div><div><br></div><div>As far as reducing enum boilerplate, what about borrowing the generic system's syntax and looking at it from the switch's PoV?</div><div>func == (lhs: MyEnum, r<span style="background-color: rgba(255, 255, 255, 0);">hs: MyEnum) -&gt; Bool {</span></div><div>&nbsp; &nbsp; switch &lt;c is MyEnum&gt; (lhs, rhs) {</div><div>&nbsp; &nbsp; case (c(let lVal), c(let rVal)): // both lhs and rhs are "c" and the same case</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return lVal == rVal //syntax error if `==` isn't defined for the associated value types of every case</div><div>&nbsp; &nbsp; default: return false</div><div>&nbsp; &nbsp; }</div><div>}</div><div><br></div><div>- Dave Sweeris</div></body></html>