On May 24, 2016, at 9:35 PM on Tue May 24 2016, Matthew Johnson <[email protected]> wrote:
> , Austin Zheng > <[email protected]> wrote: > > On Tue, May 24, 2016 at 4:24 PM, Brent Royal-Gordon > <[email protected]> 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. I'm not sure I agree that Existentials shouldn't do that. The amount of boilerplate one needs to construct a user-defined simulation of an existential in these cases can be prohibitive. Why shouldn't the compiler handle it for us? -- Dave _______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
