<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 18 Jul 2016, at 08:04, Adrian Zubarev 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 class="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: 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; background-color: rgb(254, 254, 254);"><p style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">This is something<span class="Apple-converted-space">&nbsp;</span><strong style="-webkit-margin-before: 0px;" class="">additional</strong>, but I’m curios about how the community feels about it.</p><p style="margin: 15px 0px;" class="">I recently come across the issue where conforming to<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">Hashable</code><span class="Apple-converted-space">&nbsp;</span>wasn’t enough to thecke if two instances of the same<span class="Apple-converted-space">&nbsp;</span><em class="">generic</em><span class="Apple-converted-space">&nbsp;</span>type were equal.</p><p style="margin: 15px 0px;" class="">I had additionally provide myself the<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">!=</code><span class="Apple-converted-space">&nbsp;</span>function.</p><pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">public func !=&lt;T, U&gt;(lhs: SomeTypeName&lt;T&gt;, rhs: SomeTypeName&lt;U&gt;) -&gt; Bool {
    return lhs.hashValue != rhs.hashValue
}
</code></pre><p style="margin: 15px 0px;" class="">I wondered if Swift can ever get generic specialization like this:</p><pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">public func !=&lt;T : Hashable, U, V&gt;(lhs: T&lt;U&gt;, rhs: T&lt;V&gt;) -&gt; Bool {
    return !(lhs.hashValue == rhs.hashValue)
}
</code></pre><p style="margin: 15px 0px;" class="">This function in stdlib would fill the gap. Or we need an extra protocol<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">GenericHashable</code><span class="Apple-converted-space">&nbsp;</span>which includes<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal;" class="">!=</code>.</p></div></div></blockquote></div>What exactly is the problem you're trying to solve here? Hash values being equal is not a guarantee of equality, so what you're doing with this operator is masking what's going on which I'm not sure is a good idea. If you need to compare hash-values, then compare them, they're already as generic as you can possibly get (since they're always of type Int), otherwise you can't really rely on hash-values from generic types in this way, and shouldn't be hiding them behind the equality operator.<div class=""><br class=""></div><div class="">To think of it another way, if two hash-values are equal, then the two values *might* be equal, but you still have to test them further to be sure. You can only rely on the hash-value in this way if you have control of the implementation details, which you can only guarantee when the values you are comparing are the same type, or from a family of types that you control (as you say, a protocol could do this, by requiring that hash-values are unique within some well-defined domain).</div><div class=""><br class=""></div><div class="">I feel like this is seeking a solution that is a workaround to a protocol that has no associatedtype, as the problem you're describing is essentially already solved by generic constraints. For example, if you were working with Iterators you can define things like:</div><div class=""><br class=""></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func someFunc&lt;I1:IteratorProtocol, I2:IteratorProtocol where I1.Element:Hashable, I2.Element:Hashable&gt;(lhs:I1, rhs:I2) -&gt; Bool {</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>return lhs.next()?.hashValue == rhs.next()?.hashValue</font></div><div class=""><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><br class=""></div><div class="">Probably a useless example, but it shows how generic constraints achieve this already, but they require a protocol that is intended to expose an internal detail (the Element associatedtype), this is not what Hashable is for, Hashable is for reducing any conforming type down to an Int, with no guarantee of that value being unique.</div></body></html>