[swift-evolution] Representation of natural numbers with a distinct type

Dave Abrahams dabrahams at apple.com
Thu Feb 4 02:20:21 CST 2016


on Wed Feb 03 2016, David Turnbull <dturnbull-AT-gmail.com> wrote:

> On Wed, Feb 3, 2016 at 4:35 PM, Dave Abrahams via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> I think the semantic requirements on CollectionType's count prevent it
>> from ever being negative.  If they don't, they should.
>
> Only when you actually try to iterate will it fail. 

That's not what I'm saying.  

  /// Returns the number of elements.
  /// ...
  var count: Index.Distance { get }

Awkward wording aside, this says that count is the number of elements in
the collection.  Once you have that, it's automatically non-negative.
There's no way for a collection to hold less than zero elements.

> It's useful to have this invalid state where start>end. You might have
> one thread finding minima and another finding maxima. That's how it is
> today anyways. Which I think is nice.

I have no idea what you mean here, sorry.

-- 
-Dave


More information about the swift-evolution mailing list