<div dir="ltr">Thank you for the clarification!</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 18, 2016 at 11:33 PM, Jordan Rose <span dir="ltr">&lt;<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>&gt;</span> wrote:<br><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>Uh, it wasn&#39;t particularly thought through, but basically some way to tie the type of the Set to the implementations of == and hash. This could be something like C++ non-type template parameters, or a way to provide a custom conformance (&quot;use <i>this</i> implementation of Hashable instead of the one that comes with the type&quot;) a la ML.*</div><div><br></div><div>I don&#39;t think either of these are near-term features, or possibly even far-term features. It was mostly just a way to say &quot;this belongs in the type system for both correctness and performance reasons&quot;.</div><div><br></div><div>Jordan</div><div><br></div><div><div>* I don&#39;t actually <a href="https://en.wiktionary.org/wiki/grok" target="_blank">grok</a> ML modules yet.</div></div><div><div class="h5"><div><br></div><br><div><blockquote type="cite"><div>On Feb 18, 2016, at 20:23 , T.J. Usiyan &lt;<a href="mailto:griotspeak@gmail.com" target="_blank">griotspeak@gmail.com</a>&gt; wrote:</div><br><div><div dir="ltr">What do you mean by &quot;put functions in generics&quot;?<div><br></div><div>TJ</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 18, 2016 at 11:04 PM, Jordan Rose via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Feb 18, 2016, at 16:09 , Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><br style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">on Thu Feb 18 2016, Jacob Bandes-Storch &lt;</span><a href="mailto:swift-evolution@swift.org" style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><span style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">&gt; wrote:</span><br style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite" style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Would it make sense for the standard library Set to provide variants (or<br>parallel versions of the same data structure) that take custom hashValue/==<br>implementations at init time (functions taking in Elements), rather than<br>relying on Hashable/Comparable protocols?<br><br>Use case: I want a set of objects that are compared for equality using ===<br>rather than ==. This doesn&#39;t seem possible today, using Set, without<br>creating some sort of wrapper object.<br><br>This particular case would be analogous to using NSHashTable with<br>NSPointerFunctionsObjectPointerPersonality. (Maybe all I&#39;m asking for is a<br>Swiftier API for NSHashTable — including ArrayLiteralConvertible, using<br>generics instead of UnsafePointer&lt;Void&gt;, etc.)<br><br>Similarly, C++&#39;s unordered_map<br>&lt;<a href="http://en.cppreference.com/w/cpp/container/unordered_map" target="_blank">http://en.cppreference.com/w/cpp/container/unordered_map</a>&gt; and friends have<br>template parameters specifying the hash function and equality comparator,<br>which use std::hash and == by default.<br></blockquote><br style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">It might make sense.  How bad is the wrapper solution for user code?</span><br style="font-family:Monaco;font-size:11px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"></div></blockquote></div><br></span><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>struct CustomHashableFoo: Hashable {</div><div>  var value: Foo</div><div>  func hash() -&gt; Int {</div><div>    // custom hash function here</div><div>  }</div><div>}</div><div>func ==(a: CustomHashableWrapped, b: CustomHashableWrapped) {</div><div>  // custom == here</div><div>}</div></blockquote><br><div>Really not that bad, although you do have to get &#39;value&#39; in and out of the box. It&#39;s also not reusable code—you have to rewrite the box for every type.</div><div><br></div><div>I&#39;d say you usually <i>don&#39;t</i> want to allow custom hash/== closures because (a) then you have to store them somewhere, and (b) the compiler won&#39;t usually be able to inline them away. You also end up with a Set&lt;Foo&gt; that doesn&#39;t behave like a normal Set&lt;Foo&gt;—maybe you can insert equal-but-not-identical elements—which is bad if anyone&#39;s relying on normal Set-like guarantees.</div><div><br></div><div>-1 from me until we can put functions in generics, if ever.</div><div><br></div><div>Jordan</div></div><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>
<br></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></blockquote></div><br></div>