<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"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></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'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 ("use <i>this</i> implementation of Hashable instead of the one that comes with the type") a la ML.*</div><div><br></div><div>I don't think either of these are near-term features, or possibly even far-term features. It was mostly just a way to say "this belongs in the type system for both correctness and performance reasons".</div><div><br></div><div>Jordan</div><div><br></div><div><div>* I don'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 <<a href="mailto:griotspeak@gmail.com" target="_blank">griotspeak@gmail.com</a>> wrote:</div><br><div><div dir="ltr">What do you mean by "put functions in generics"?<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"><<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 style="word-wrap:break-word"><span><br><div><blockquote type="cite"><div>On Feb 18, 2016, at 16:09 , Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> 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 <</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">> 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'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'm asking for is a<br>Swiftier API for NSHashTable — including ArrayLiteralConvertible, using<br>generics instead of UnsafePointer<Void>, etc.)<br><br>Similarly, C++'s unordered_map<br><<a href="http://en.cppreference.com/w/cpp/container/unordered_map" target="_blank">http://en.cppreference.com/w/cpp/container/unordered_map</a>> 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() -> 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 'value' in and out of the box. It's also not reusable code—you have to rewrite the box for every type.</div><div><br></div><div>I'd say you usually <i>don't</i> want to allow custom hash/== closures because (a) then you have to store them somewhere, and (b) the compiler won't usually be able to inline them away. You also end up with a Set<Foo> that doesn't behave like a normal Set<Foo>—maybe you can insert equal-but-not-identical elements—which is bad if anyone'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>