It's possible that I haven't captured your intent well with my suggestion.
Yes, I believe this follows from SE-0068 and your proposal.
All of the above fits well as a consequence of your proposal.
The second version I have in mind is a shorthand form of qualified lookup that can be used to disambiguate certain scenarios like for instance this made up example:
struct FirstDimension<Element> {
// `FirstDimension.Element` is the shorthand form.
// In this case we cannot write `FirstDimension<Element>.Element` because we would
// then refer to the `Element` of the `SecondDimension` generic struct.
struct SecondDimension<Element> where Element == FirstDimension.Element {
...
}
}
The reference to FirstDimension.Element
does work, because FirstDimension.Element
is interpreted as FirstElement<Element>.Element
(using the outer "Element" generic parameter). Personally, I regret the rule that makes FirstDimension
shorthand for FirstDimension<Element>
; it causes confusion with type inference, and SE-0068 is a better answer here. Regardless, the example above will work with your proposal.
On "ignoring some generic type parameters when needed":
That works well for protocols because "T: TestProtocol" is a conformance constraint. That's the main concern I have with your original example:
Here, T: Generic
isn't a conformance constraint, or a superclass constraint: it's a same-type constraint where the actual type arguments to Generic
imply (hidden) type parameters. Personally, I find that to be too magical to reason about, and in the examples I've seen so far don't feel like improvements.
By API, I mean that they are part of the contract between the designer of the generic type and any user of the generic type. You can't change the name of a generic parameter without breaking client code, because the type parameter names are used by extensions.
Doug