on Sun Jan 29 2017, Dave Abrahams <[email protected]> wrote:

> on Sat Jan 28 2017, Brent Royal-Gordon <brent-AT-architechies.com> wrote:
>
>>> On Jan 28, 2017, at 11:48 AM, Dave Abrahams via swift-evolution 
>>> <[email protected]>
> wrote:
>>> 
>>> The way to handle Deque is to add this requirement to Collection when
>>> we get the language features to express it:
>>> 
>>
>>>  protocol Collection {
>>> 
>>>    associatedtype Segments : Collection 
>>>    where Segments.Element : Collection,
>>>      Segments.Element.Element == Element
>>>     = EmptyCollection<EmptyCollection<Element>>
>>> 
>>>    var segments: Segments? {get}
>>>    ...
>>>  }
>>> 
>>>  extension Collection 
>>>  where Segments == EmptyCollection<EmptyCollection<Element>> {
>>>    var segments: Segments? { return nil }
>>>  }
>>
>> Couldn't that be be expressed more accurately with `Never` if it were a 
>> subtype-of-all-types?
>>
>>       protocol Collection {
>>
>>         associatedtype Segments : Collection 
>>         where Segments.Element : Collection,
>>           Segments.Element.Element == Element
>>          = Never
>>
>>         var segments: Segments? {get}
>>         ...
>>       }
>>
>>       extension Collection 
>>       where Segments == Never {
>>         var segments: Segments? { return nil }
>>       }
>
> Maybe, if we had the language feature, we could do that... but we don't.
>
>> Or you could say that there is always at least *one* segment:
>>
>>       protocol Collection {
>>
>>         associatedtype Segments : Collection 
>>         where Segments.Element : Collection,
>>           Segments.Element.Element == Element
>>          = CollectionOfOne<Self>
>>
>>         var segments: Segments {get}
>>         ...
>>       }
>>
>>       extension Collection 
>>       where Segments == CollectionOfOne<Self> {
>>         var segments: Segments { return CollectionOfOne(self) }
>>       }
>
> That's not actually helpful, because segmented algorithms need to be
> able to use the presence of segments to stop recursing :-)

Er, the absence of segments I mean.

-- 
-Dave

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to