Sent from my iPad
> On May 24, 2016, at 9:35 PM, Austin Zheng <austinzh...@gmail.com> wrote: > > > >> On Tue, May 24, 2016 at 4:24 PM, Brent Royal-Gordon <br...@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. The primary difference is the freedom to accept an index which is invalid and call fatalError when you get it. We don't want existentials to do something that. But with user-defined types we have the flexibility to do that if we decide it is the right design. > >> -- >> Brent Royal-Gordon >> Architechies >> >
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution