[swift-evolution] [Pre-proposal] Replace [Foo] With CollectionType

Austin Zheng austinzheng at gmail.com
Tue May 24 21:35:43 CDT 2016


On Tue, May 24, 2016 at 4:24 PM, Brent Royal-Gordon <brent at architechies.com>
wrote:

> > I’m not sure what you mean about introducing type unsafely.
>
> What I mean is that once you do this:
>
>         let x: AnyCollection<Character> = myArrayOfCharacters
>         let y: AnyCollection<Character> = myString.characters
>
> Both `x` and `y` have indices of type `Any<Comparable>`, and will now
> accept each others' indices:
>
>         for i in x.indices {
>                 print(y[i])             // Oops!
>         }
>
> 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.
>
>
If there's any way that the rules that I've proposed can be relaxed without
sacrificing type safety, I would love to hear it. I think the difference in
'power' in this regard between a function that uses generic types and a
function that uses existentials is something inherent to how each works,
though.


> --
> Brent Royal-Gordon
> Architechies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160524/ed90d138/attachment.html>


More information about the swift-evolution mailing list