[swift-evolution] Generic parameters in "as?" checks
Charles Srstka
cocoadev at charlessoft.com
Thu Jan 21 00:21:38 CST 2016
> On Jan 20, 2016, at 11:56 PM, Slava Pestov <spestov at apple.com> wrote:
>
>> Okay, in the example above, that leaves five places for the generic signature to go: after the “if”, after the “let”, after the variable name, after the equals sign, and after the “as?”. Or perhaps we could introduce some sort of new keyword in there to which to attach the generic signature.
>
> Various approaches have been discussed before. The one that’s closest to what you describe above is to have some kind of ‘open’ keyword,
>
> func foo(p: SomeProto) {
> let t = open p as T {
> T.SomeAssocType.someStaticMethod(…)
> }
> }
Thanks, this looks good. Based on this, I found the earlier discussion where this came up, but it seems that the example above assumes you already know p is SomeProto. I assume there’d be a way to take p as something else, like an Any, and dynamically cast it to SomeProto using some combination of as? and open, right?
>>>> Is this a feasible thing to ask for?
>>>
>>> I think so, but we have to careful with the design. This ties in with some of the discussions on generalizing existential types, also.
>>
>>
>> That’s good to hear. Is there any information on what the Swift team is planning to do with existentials?
>
> Oh, I was just referring to the discussion on this list. No concrete proposals have been accepted so far, AFAIK.
Well, if someone proposes one, it’ll get a +1 from me.
Thanks,
Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160121/58cdcee8/attachment.html>
More information about the swift-evolution
mailing list