This touches on my main concern with SE-0244, which is that the some P
syntax may not extend well once we add where
clauses, multiple opaque returns, or other plausible features.
I'd like to suggest an alternative solution: Make some
always* be an anonymous shorthand for some syntax involving named generic parameters. For instance (strawman syntax abounds here):
Generic parameter | |
Anonymous | func f1(_: some Collection) |
Named | func f1<C: Collection>(_: C) |
Where clause | func f1<C>(_: C) where C: Collection |
Opaque result type | |
Anonymous | func f2() -> some Collection |
Named | func f2<result C: Collection>() -> C |
Where clause | func f2<result C>() -> C where C: Collection |
Opaque typealias | |
Anonymous | typealias OpaqueCollection: some Collection = ConcreteCollection |
Named | typealias OpaqueCollection<result C: Collection> = ConcreteCollection |
Where clause | typealias OpaqueCollection<result C> = ConcreteCollection where C: Collection |
Generalized existential | |
Anonymous | Any<some Collection> |
Named | Any<C: Collection> |
Where clause | Any<C where C: Collection> |
If you used a named form, you could reuse the same type in multiple positions, constrain it, etc. (Or at least you could write those things—the compiler might not support some of them.) If you used an anonymous form, you wouldn't be able to express those things, but you could always transform to a named form. We might even be able to provide a local refactoring to do it for you.
* I'm not necessarily suggesting that SE-0244 needs to be rejected because it doesn't have a named form yet, but if we went in this direction, we'd want to add one in the next release.