<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><br><div>On Oct 16, 2017, at 10:42, BJ Homer via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><blockquote type="cite" class="">On Oct 16, 2017, at 8:20 AM, Thorsten Seitz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</blockquote><div><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""><blockquote type="cite" class="">Am 16.10.2017 um 07:19 schrieb Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt;:</blockquote></div><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class="">What useful generic algorithms would this protocol support that are not already possible?</div></div></div></div></div></blockquote><div class=""><br class=""></div>It would allow expressing generic algorithms depending on an order.</div><div class=""><br class=""></div><div class="">-Thorsten</div></div></div></blockquote></div><br class=""><div class="">We can already express generic algorithms that depend on an order—any generic algorithm that works on a&nbsp;<font face="Courier" class="">Sequence</font> works on something that is ordered. A Swift <font face="Courier" class="">Set</font>&nbsp;has an undefined order right now, but a generic algorithm working on any arbitrary Sequence likely doesn’t care about <i class="">what</i>&nbsp;the order, just that an order exists. And a Swift <font face="Courier" class="">Set</font> does indeed have an order. If you have a generic algorithm that only works on inputs sorted in a particular manner, then you’ve likely either documented that or added a “sortedBy” parameter. Otherwise, you probably just want to be able to iterate through everything.</div><div class=""><br class=""></div><div class="">Let’s assume, though, that you wanted to write an algorithm that works only on <font face="Courier" class="">MeaningfullyOrdered</font> inputs.&nbsp;</div><div class=""><br class=""></div><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(186, 45, 162);" class="">func</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class=""> extractInfo&lt;T: </span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(112, 61, 170);" class="">MeaningfullyOrdered</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">&gt;(</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(186, 45, 162);" class="">_</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class=""> input: </span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255); color: rgb(79, 129, 135);" class="">T</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">) {</span><span style="background-color: rgb(255, 255, 255);" class="">&nbsp;</span><span style="font-family: Menlo; font-size: 11px; background-color: rgb(255, 255, 255);" class="">}</span><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class="">extractInfo<span style="color: #000000" class="">(someArray)</span></div></div><div class=""><br class=""></div><div class="">What stops the caller from simply wrapping the Set in an Array?</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class="">extractInfo<span style="color: #000000" class="">(</span><span style="color: #703daa" class="">Array</span><span style="color: #000000" class="">(someSet))</span></div></div><div class=""><br class=""></div><div class="">The Array constructed here is going to reflect the arbitrary ordering provided by Set, but as far as the type system is concerned, the input is an Array, which is certainly meaningfully-ordered. Have we gained anything by requiring the caller to wrap the input in an array? We’ve made the call site a bit more awkward, and we’ve lost a bit of performance. We certainly need to be able to convert Sets in to Arrays; to eliminate that would be massively source-breaking, and it’s not clear that allowing that conversion is actively harmful, so it’s unlikely to change in Swift 5.</div></div></blockquote><div><br></div><div>Should/could we just rename `Set` to `UniquedArray` or something like that? This is starting to feel a bit like the access control debate.</div><div><br></div><div>- Dave Sweeris</div></div></body></html>