> 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 }
         }

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) }
         }

-- 
Brent Royal-Gordon
Architechies

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

Reply via email to