Oh, this is weird... I replied to a different thread an hour ago. Somehow that message hasn't posted yet, but this one from three days ago apparently got reposted? Weird. > On Oct 19, 2017, at 12:11 PM, David Sweeris via swift-evolution > <swift-evolution@swift.org> wrote: > > > On Oct 16, 2017, at 10:42, BJ Homer via swift-evolution > <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote: > >>> On Oct 16, 2017, at 8:20 AM, Thorsten Seitz via swift-evolution >>> <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote: >>> >>>> Am 16.10.2017 um 07:19 schrieb Xiaodi Wu <xiaodi...@gmail.com >>>> <mailto:xiaodi...@gmail.com>>: >>> >>>> What useful generic algorithms would this protocol support that are not >>>> already possible? >>> >>> It would allow expressing generic algorithms depending on an order. >>> >>> -Thorsten >> >> We can already express generic algorithms that depend on an order—any >> generic algorithm that works on a Sequence works on something that is >> ordered. A Swift Set has an undefined order right now, but a generic >> algorithm working on any arbitrary Sequence likely doesn’t care about what >> the order, just that an order exists. And a Swift Set 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. >> >> Let’s assume, though, that you wanted to write an algorithm that works only >> on MeaningfullyOrdered inputs. >> >> func extractInfo<T: MeaningfullyOrdered>(_ input: T) { } >> extractInfo(someArray) >> >> What stops the caller from simply wrapping the Set in an Array? >> >> extractInfo(Array(someSet)) >> >> 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. > > Should/could we just rename `Set` to `UniquedArray` or something like that? > This is starting to feel a bit like the access control debate. > > - Dave Sweeris > _______________________________________________ > swift-evolution mailing list > swift-evolution@swift.org > https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution