On Thu, Mar 13, 2025, at 10:35 AM, Tim Düsterhus wrote: > Hi > > Am 2025-03-11 22:45, schrieb Larry Garfield: >> We should not block this kind of improvement on the hope of generics. >> Worst case, we have this plus generics so you have options, how >> terrible. > > In this case, I agree. This is an obvious addition to the type system > that uses the existing infrastructure of the type system. > > But generally speaking, having too many options is not a good thing. It > makes the language larger and more complex to learn, requires > documentation effort, support by IDEs and static analyzers and similar > things.
It's definitely a balancing act, yes. TIMTOWTDI definitely has downsides, but at the same time, having multiple ways to accomplish the same goal isn't inherently wrong, unless they conflict with each other in some way. >> Rust-style associated types would probably work as well. I'd be fine >> with that approach, too. One could argue they're more valuable as a >> sort of "junior generics," but absent anyone able and willing to >> implement them, again, worst-case we end up with options in the future. > > … so for associated types, I do not necessarily agree. They seem to be a > strict subset of the functionality enabled by generics, or the > functionality enabled by type aliases combined with “inner classes / > inner types”. Since introducing associated types would bring entirely > new syntax and semantics to the language, it is less obvious to me that > they are a useful (intermediate) addition to the language. The counter argument here is that a number of languages (like Rust) have both generics and associated types, so they can coexist and serve slightly different use cases. I have not used Rust enough to have an opinion on how and when to use one or the other, but having one doesn't seem to impede the other. >From my (admittedly limited) understanding, associated types sounds rather >like the "inheritance only" pseudo-generics that Derick had proposed for >collections last year, in a more general form. (cf: >https://thephp.foundation/blog/2024/08/19/state-of-generics-and-collections/#collections) --Larry Garfield