<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 28, 2016, at 8:43 PM, Pedro Vieira 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="ltr" 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="">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 class="">The following would be enough:<br class=""><div class=""><br class=""></div><div class=""><div class="">struct Foo: Equatable, Hashable {</div><div class="">&nbsp; ...</div><div class="">}</div><div class=""><br class=""></div><div class="">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></div></div></blockquote><div><br class=""></div><div>The problem with this is that it doesn’t differentiate between synthesized and manual conformance. &nbsp;You won’t get error messages you otherwise would when you intend to supply manual conformance. &nbsp;It is also less clear to a reader of the code that the default, compiler synthesized implementation is being generated.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" 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="gmail_quote"><div dir="ltr" class="">Michael Peternell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; escreveu no dia quinta, 26/05/2016 às 10:58:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Can we just copy&amp;paste the solution from Haskell instead of creating our own? It's just better in every aspect. Deriving `Equatable` and `Hashable` would become<br class=""><br class="">struct Polygon deriving Equatable, Hashable {<br class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span>...<br class="">}<br class=""><br class="">This has several advantages:<br class="">- you don't have to guess wether `Equatable` or `Hashable` should be automatically derived or not.<br class="">- Deriving becomes an explicit choice.<br class="">- If you need a custom `Equatable` implementation (for whatever reason), you can still do it.<br class="">- It doesn't break any code that is unaware of the change<br class="">- It can be extended in future versions of Swift, without introducing any new incompatibilities. For example, `CustomStringConvertible` could be derived just as easily.<br class="">- It is compatible with generics. E.g. `struct Shape&lt;T&gt; deriving Equatable` will make every `Shape&lt;X&gt;` equatable if `X` is equatable. But if `X` is not equatable, `Shape&lt;X&gt;` can be used as well. (Unless `X` is not used, in which case every `Shape&lt;T&gt;` would be equatable. Unless something in the definition of `Shape` makes deriving `Equatable` impossible =&gt; this produces an error.)<br class="">- It is proven to work in production.<br class=""><br class="">-Michael<br class=""></blockquote><div class=""><span style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px;" class=""><br class=""></span></div><div class=""><span style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px;" class="">Pedro Vieira</span><br class=""></div><div style="font-size: 13px; color: rgb(34, 34, 34); font-family: arial, sans-serif;" class=""><a href="http://pedrovieira.me/" class="">http://pedrovieira.me</a></div></div></div><div dir="ltr" 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="">--<span class="Apple-converted-space">&nbsp;</span><br class=""></div><div data-smartmail="gmail_signature" 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 dir="ltr" class=""><span style="color: rgb(34, 34, 34); font-family: arial, sans-serif;" class="">Pedro Vieira</span><div style="color: rgb(34, 34, 34); font-family: arial, sans-serif;" class=""><a href="http://pedrovieira.me/" class="">http://pedrovieira.me</a></div></div></div><span 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; float: none; display: inline !important;" class="">_______________________________________________</span><br 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=""><span 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; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br 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=""><a href="mailto:swift-evolution@swift.org" 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="">swift-evolution@swift.org</a><br 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" 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="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>