I for one would be interested in your elaboration. Based on Dave's comments, I'm pretty convinced that the Comparable requirement is best left in place.<br><div class="gmail_quote"><div dir="ltr">On Wed, Jul 6, 2016 at 19:19 plx via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">My own 2c is to drop the comparable requirement.<br>
<br>
I can elaborate if necessary, but wanted to at least cast my “+1” for removing the requirement.<br>
<br>
> On Jul 5, 2016, at 9:39 PM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>
><br>
><br>
> I've already raised the question here of whether we should weaken the<br>
> requirement that Collection.Index be Comparable to merely being<br>
> Equatable.<br>
><br>
> Part of the motivation was to support data structures that otherwise<br>
> would be expensive or impossible to implement. For example, with<br>
> Comparable indices, you can't build a linked list that supports<br>
> restructuring (e.g. insert, delete, splice) in O(1) without invalidating<br>
> indices... not even an unsafe linked list with reference semantics.<br>
> [While I don't think linked lists are terribly good data structures for<br>
> most things, they are still useful in teaching, and it bothered me that<br>
> we were ruling them out.] Even if you take away the index invalidation<br>
> restriction, you have to store a counter in the index, which is an awkward inefficiency.<br>
> Supporting Comparable indices for a tree data structure requires<br>
> encoding the path from the root to the node. It's only one or two words<br>
> in practice, but it's another awkward inefficiency.<br>
><br>
> Over the weekend, I tried lifting the restriction to see what kind of<br>
> effect it would have on the standard library.<br>
> <a href="https://github.com/apple/swift/pull/3325" rel="noreferrer" target="_blank">https://github.com/apple/swift/pull/3325</a><br>
><br>
> Although I *had* been leaning strongly toward making this change, having<br>
> looked at the effects, I am now more ambivalent:<br>
><br>
> * A Range<T>, where T is not Comparable, could be constructed with any<br>
> pair of Equatable T instances. We'd only detect that the Range may be<br>
> invalid when T happened to also be Comparable. However, the fact that<br>
> you are creating a Range already sort of implies an underlying<br>
> ordering.<br>
><br>
> * A Collection with non-Comparable indices still imposes an ordering<br>
> upon the indices.<br>
><br>
> * In a Collection with Comparable indices, the ordering implied by <<br>
> needs to match the ordering of indices in the collection. Otherwise,<br>
> there would be no way to form Ranges (for use in slicing, for example)<br>
> without causing a trap. This is *weird*! There's little precedent<br>
> for imposing stronger semantic requirements on an associated type if<br>
> it conforms to a particular protocol (Comparable in this case), except<br>
> where the requirement is part of the protocol.<br>
><br>
> Also, Dmitri reminded me that even with a Comparable requirement on<br>
> indices, there is still no problem converting an equatable iteration<br>
> state into an index; you just need to augment it with an integer<br>
> counter. So it's still trivial to create a Collection from nearly<br>
> everything that is today a multipass Sequence. It does make indexing<br>
> slightly more expensive, but it's likely we'd optimize that overhead<br>
> away in many critical situations.<br>
><br>
> Anyway, the thoughts of the community on this topic would be interesting<br>
> to us. We need to make a decision about this very soon.<br>
><br>
> Thanks!<br>
><br>
> --<br>
> Dave<br>
><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>
<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>
</blockquote></div>