[swift-evolution] [Pre-proposal] Replace [Foo] With CollectionType
austinzheng at gmail.com
Tue May 24 21:31:33 CDT 2016
Sorry. That sentence should read: [Foo] is an array. Collection<Foo> means
nothing in Swift right now, but it really does look awfully like a generic
protocol by analogy.
Since I'm here, I might as well keep on digging...
Right now, we have good syntax delineation. Generic types and functions are
immediately obvious because of the characteristic angle brackets placed
after the function or type name (with the exception of the three big
sugared generic types in the stdlib - Array, Dictionary, and Optional). We
also have protocol<...> to build an existential out of one or more
protocols, although there has been some discussion in other threads about
whether people might confuse that syntax with generic type syntax and
whether it should be changed as a result. Associated types don't use the
angle brackets, but they aren't really generic types - they can be used to
constrain generic types, but they also show up in places like defining
constrained protocol extensions, whose methods don't necessarily need to be
used in a generic function.
I think the fact that it's reasonably easy to tell these three loosely
defined families of type features apart is a valuable aspect of the
language's design, and loosening this ability should be done very carefully.
On Tue, May 24, 2016 at 7:19 PM, Austin Zheng <austinzheng at gmail.com> wrote:
> I regret mentioning existentials; I am aware that an existential that
> isn't sufficiently constrained will never be able to provide the same
> guarantees as a generic type variable. My argument is that even a partially
> constrained existential is useful if there is a useful set of APIs that
> don't touch the associated types in question. I do not believe that they
> fulfill the same role as generics, and I apologize for writing a response
> that strongly implied they were.
> That being said, my opinion regarding this suggestion is still this: [Foo]
> is not an array, Collection<Foo> is not a generic protocol, and I am
> strongly against any sort of compiler magic that makes those types mean
> anything other than what they appear to be.
> If this rule:
>> > The generalized existentials proposal goes out of its way to be
>> explicit about the fact that only type safe operations would be visible
>> through the existential.
>> Is trying to say that this isn't the case because APIs using the
>> collection's `Index` are not exposed on an `AnyCollection`, well, then I'm
>> not sure what `AnyCollection` is actually supposed to be used for.
>> Brent Royal-Gordon
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution