[swift-evolution] Generic parameters in "as?" checks

Slava Pestov spestov at apple.com
Wed Jan 20 23:56:46 CST 2016

> On Jan 20, 2016, at 9:53 PM, Charles Srstka <cocoadev at charlessoft.com> wrote:

> If we want to get *really* specific, I’m actually dealing with a protocol with associated types, not a generic struct. However, they both fall under the same umbrella of “need to use this as a generic constraint”, and “generic” is less obnoxious to type over and over when discussing things than “protocol with associated types”. :-P

I think this falls under the “generalizing existentials to support protocols with associated types” bucket.
> 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 {

But another promising approach is path-dependent types, so that above you could write p.SomeAssocType for instance.

>>> 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.



> Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160120/5db68035/attachment.html>

More information about the swift-evolution mailing list