[swift-evolution] Generic Subscripts
rjmccall at apple.com
Sun Jan 15 18:05:57 CST 2017
> On Jan 13, 2017, at 9:33 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> On Jan 13, 2017, at 9:50 AM, John McCall via swift-evolution <swift-evolution at swift.org> wrote:
>> I'm also not sure we'd ever want the element type to be inferred from context like this. Generic subscripts as I see it are about being generic over *indexes*, not somehow about presenting a polymorphic value.
> I think I have a pretty good use case for generic element types: you may want an index to carry the type of its element. For example, suppose you want to have a sort of dictionary whose keys are unique instances of a key class, and whose value type depends on the key instance:
Oh, sorry, I didn't mean to suggest that the value type shouldn't be allowed to depend on the subscript's type parameters at all, just that it should probably be determinable from the index type. I'm not sure that I have a specific technical concern, though, as long as it's a given that any particular access assigns a single type to the value; but I'll need to think about it.
More information about the swift-evolution