> On May 24, 2016, at 5:55 PM, Brent Royal-Gordon via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
>> Better support for existentials (see the generics manifesto, 
>> https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md) should 
>> obviate the need for any sort of sugar or compiler magic to do this kind of 
>> thing.
>> 
>> typealias AnyCollection<T> = Any<Collection where .Element == T, ...>
>> func doSomething(collection: AnyCollection<Foo>)
> 
> That isn't really the same thing, though. Any<Collection> is an existential; 
> it introduces indirection which would not be present in the generic version 
> and, in this case, it erases several associated types, potentially 
> introducing type-unsafety as well.

You are right about the indirection.  I mentioned that Joe has talked about 
making generic arguments have identical behavior to existentials.  I just 
realized that his comment was with respect to current existentials which don’t 
have associated types.  It might also be possible to extend this to 
existentials which bind all associated types to concrete types, but it would 
not apply to something like AnyCollection<Foo> which leaves several associated 
types unbound.  So as I mentioned, if we do introduce shorthand for something 
like AnyCollection we would need to decide whether the shorthand produces an 
implicit generic parameter or uses the existential.

I’m not sure what you mean about introducing type unsafely.  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.

> 
> -- 
> Brent Royal-Gordon
> Architechies
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to