<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I read this great post. But it shows an example where the problem is circumvented because the algorithm can work on a more general protocol. But the problem still persists for algorithms which make sense for any countable range (open and closed).</div><div><br>On 13 Jan 2017, at 02:57, Adriano Ferreira &lt;<a href="mailto:adriano.ferreira@me.com">adriano.ferreira@me.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8">Hi Dave,<div class=""><br class=""></div><div class="">I’m not arguing about correctness cause I understand the reasoning behind it, but about the abstraction itself.</div><div class=""><br class=""></div><div class="">I believe a simplified interface would be more fun to use and less confusing.&nbsp;<a href="https://oleb.net/blog/2016/10/generic-range-algorithms/" class="">This post</a>&nbsp;from Ole&nbsp;Begemann talks a little bit about this interesting idea.</div><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">—A</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 12, 2017, at 5:55 PM, David Sweeris &lt;<a href="mailto:davesweeris@mac.com" class="">davesweeris@mac.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On Jan 12, 2017, at 15:44, Adriano Ferreira via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">BTW, I agree with you, having the range type split is somewhat confusing, specially for those new to the language.<br class=""></blockquote><br class="">Do you mean that you think having two types is confusing, or that the way we currently split them is confusing?<br class=""><br class="">If it's the former, then I disagree... IIRC, open vs closed ranges is covered in high school math, and IMHO it's not too hard to see the usefulness of both "0..&lt;5" and "1...5".<br class=""><br class="">If it's the latter, I think it's only confusing because, well, partly because we only implement half the kinds of ranges ("lower" is always closed, but that's another thread), but mostly because we don't have generic protocols yet. If we could write<br class=""> &nbsp;&nbsp;&nbsp;protocol Range&lt;T&gt; where T : WhateverTheCurrentConstraintsAre {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var lower: T {get}<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var upper: T {get}<br class=""> &nbsp;&nbsp;&nbsp;}<br class="">Then we could define the concrete types as<br class=""> &nbsp;&nbsp;&nbsp;struct CCRange&lt;T&gt;: Range&lt;T&gt; {...}<br class=""> &nbsp;&nbsp;&nbsp;struct CORange&lt;T&gt;: Range&lt;T&gt; {...}<br class=""> &nbsp;&nbsp;&nbsp;struct OCRange&lt;T&gt;: Range&lt;T&gt; {...}<br class=""> &nbsp;&nbsp;&nbsp;struct OORange&lt;T&gt;: Range&lt;T&gt; {...}<br class="">(Or spell it out, "ClosedClosedRange", if you don't like the abbreviations.) Then in code, since `Range` doesn't have any "Self or associated type requirements", you can make just make it the type of a variable. In fact, if I'm not mistaken, the "..&lt;" and "..." operators could even return a `Range` instead of the relevant concrete type<br class=""> &nbsp;&nbsp;&nbsp;var x = 0..&lt;5 // "..&lt;" returns `CORange as Range`<br class=""> &nbsp;&nbsp;&nbsp;x = 0...4 // "..." returns `CCRange as Range`, which is fine because x's type is `Range`, not `HalfOpenRange` (or whatever it's called now)<br class="">We'd get full polymorphism between all the types of range without losing the value semantics we want, and the current method of overloading functions is still available if you need the speed of static dispatch.<br class=""><br class="">- Dave Sweeris <br class=""><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote></body></html>