<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="Content-Type" content="text/html charset=utf-8"><meta http-equiv="Content-Type" content="text/html charset=utf-8"><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=""><div class="">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 class="">this</i> implementation of Hashable instead of the one that comes with the type") a la ML.*</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""></div><div class=""><div class="">* I don't actually <a href="https://en.wiktionary.org/wiki/grok" class="">grok</a> ML modules yet.</div></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 18, 2016, at 20:23 , T.J. Usiyan <<a href="mailto:griotspeak@gmail.com" class="">griotspeak@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">What do you mean by "put functions in generics"?<div class=""><br class=""></div><div class="">TJ</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Feb 18, 2016 at 11:04 PM, Jordan Rose via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 18, 2016, at 16:09 , Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><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" class=""><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" class="">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" class="">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" class="">> 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" class=""><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" class=""><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" class="">Would it make sense for the standard library Set to provide variants (or<br class="">parallel versions of the same data structure) that take custom hashValue/==<br class="">implementations at init time (functions taking in Elements), rather than<br class="">relying on Hashable/Comparable protocols?<br class=""><br class="">Use case: I want a set of objects that are compared for equality using ===<br class="">rather than ==. This doesn't seem possible today, using Set, without<br class="">creating some sort of wrapper object.<br class=""><br class="">This particular case would be analogous to using NSHashTable with<br class="">NSPointerFunctionsObjectPointerPersonality. (Maybe all I'm asking for is a<br class="">Swiftier API for NSHashTable — including ArrayLiteralConvertible, using<br class="">generics instead of UnsafePointer<Void>, etc.)<br class=""><br class="">Similarly, C++'s unordered_map<br class=""><<a href="http://en.cppreference.com/w/cpp/container/unordered_map" target="_blank" class="">http://en.cppreference.com/w/cpp/container/unordered_map</a>> and friends have<br class="">template parameters specifying the hash function and equality comparator,<br class="">which use std::hash and == by default.<br class=""></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" class=""><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" class="">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" class=""></div></blockquote></div><br class=""></span><blockquote style="margin:0 0 0 40px;border:none;padding:0px" class=""><div class="">struct CustomHashableFoo: Hashable {</div><div class=""> var value: Foo</div><div class=""> func hash() -> Int {</div><div class=""> // custom hash function here</div><div class=""> }</div><div class="">}</div><div class="">func ==(a: CustomHashableWrapped, b: CustomHashableWrapped) {</div><div class=""> // custom == here</div><div class="">}</div></blockquote><br class=""><div class="">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 class=""><br class=""></div><div class="">I'd say you usually <i class="">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 class=""><br class=""></div><div class="">-1 from me until we can put functions in generics, if ever.</div><div class=""><br class=""></div><div class="">Jordan</div></div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>