[swift-evolution] Enhanced existential types proposal discussion

David Hart david at hartbit.com
Tue May 24 01:15:09 CDT 2016


It's actually a proposal waiting to be merged: https://github.com/apple/swift-evolution/pull/284

On 24 May 2016, at 04:52, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:

>> One initial bit of feedback -  I believe if you have existential types, I believe you can define Sequence Element directly, rather than with a type alias. e.g.
>> 
>> protocol Sequence {
>>  associatedtype Element
>>  associatedtype Iterator: any<IteratorProtocol where IteratorProtocol.Element==Element> 
>>  associatedtype SubSequence: any<Sequence where Sequence.Element == Element>
>>>> }
> 
> That's not really the same thing. Any<IteratorProtocol> is an existential, not a protocol. It's basically an automatically-generated version of our current `AnyIterator<T>` type (though with some additional flexibility). It can't appear on the right side of a `:`, any more than AnyIterator could.
> 
> What *would* work is allowing `where` clauses on associated types:
> 
>> protocol Sequence {
>>  associatedtype Element
>>  associatedtype Iterator: IteratorProtocol where Iterator.Element==Element
>>  associatedtype SubSequence: Sequence where SubSequence.Element == Element
>>>> }
> 
> I believe this is part of the generics manifesto.
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list