<div dir="ltr">It isn't explicit that you are synthesizing code. This is especially true because we can still declare conformance on one declaration/extension and implement in another. You could even conform in another file. This isn't generally good form but it is valid code and it is even, in some cases, somewhat reasonable.(You might have moved an extension or it might be relevant to some other bit of code somewhere but you want the conformance visible on the declaration because it is of prime importance.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, May 28, 2016 at 7:43 PM, Pedro Vieira via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I really think this would be a great addition to Swift. Although, I don't see the need to use a new keyword `deriving` for this feature.<div>The following would be enough:<br><div><br></div><div><div>struct Foo: Equatable, Hashable {</div><div> ...</div><div>}</div><div><br></div><div>It's explicit and it uses features already in the language. With this, the compiler would generate all the functions needed for `Foo` to conform to `Equatable` and `Hashable` and, in case the developer wants custom behavior on any of those functions, he/she could just write it from scratch and the compiler would use it over the generated one.</div></div></div><br><div class="gmail_quote"><span class=""><div dir="ltr">Michael Peternell via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> escreveu no dia quinta, 26/05/2016 às 10:58:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Can we just copy&paste the solution from Haskell instead of creating our own? It's just better in every aspect. Deriving `Equatable` and `Hashable` would become<br>
<br>
struct Polygon deriving Equatable, Hashable {<br>
...<br>
}<br>
<br>
This has several advantages:<br>
- you don't have to guess wether `Equatable` or `Hashable` should be automatically derived or not.<br>
- Deriving becomes an explicit choice.<br>
- If you need a custom `Equatable` implementation (for whatever reason), you can still do it.<br>
- It doesn't break any code that is unaware of the change<br>
- It can be extended in future versions of Swift, without introducing any new incompatibilities. For example, `CustomStringConvertible` could be derived just as easily.<br>
- It is compatible with generics. E.g. `struct Shape<T> deriving Equatable` will make every `Shape<X>` equatable if `X` is equatable. But if `X` is not equatable, `Shape<X>` can be used as well. (Unless `X` is not used, in which case every `Shape<T>` would be equatable. Unless something in the definition of `Shape` makes deriving `Equatable` impossible => this produces an error.)<br>
- It is proven to work in production.<br>
<br>
-Michael<br></blockquote><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px"><br></span></div></span><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:13px">Pedro Vieira</span><br></div><div style="font-size:13px;color:rgb(34,34,34);font-family:arial,sans-serif"><a href="http://pedrovieira.me/" target="_blank">http://pedrovieira.me</a></div></div></div><span class="HOEnZb"><font color="#888888"><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><span style="color:rgb(34,34,34);font-family:arial,sans-serif">Pedro Vieira</span><div style="color:rgb(34,34,34);font-family:arial,sans-serif"><a href="http://pedrovieira.me/" target="_blank">http://pedrovieira.me</a></div></div></div>
</font></span><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>