On Mon, Aug 19, 2024, at 5:16 PM, Bob Weinand wrote:

> Regarding the Collections PR, I personally really don't like it:
>
>  • It implements something which would be trivial if we had reified 
> generics. If this ever gets merged, and generics happen later, it would 
> be probably outdated and quirkiness the language has to carry around.
>  • It's not powerful. But rather a quite limited implementation. No 
> overrides of the built-in methods possible. No custom operations ("I 
> want a dict where a specific property on the key is the actual unique 
> key", "I want a custom callback be executed for each modification"). 
> It's okay as a PoC, but far from a complete enough implementation.

I think we weren't that clear on that section, then.  The intent is that 
dedicated collection classes are, well, classes.  They can contain additional 
methods, and probably can override the parent methods; though the latter may 
have some trickiness if trying to access the internal data structure, which may 
or may not look array-ish.  (That's why it's just a PoC and we're asking for 
feedback if it's worth trying to investigate further.)

>  • It's a very specialized structure/syntax, not extensible for 
> userland at all. Some functionality like generic traits, where you'd 
> actually monomorphize the contained methods would be much more 
> flexible. E.g. class Articles { use Sequence<Article>; }. Much less 
> specialized syntax, much more extensible. And generic traits would be 
> doable, regardless of the rest of the generics investigation.
> In fact, generic traits (essentially statically replacing the generic 
> arguments at link-time) would be an useful feature which would remain 
> useful even if we had fully reified generics.
> I recognize that some functionality will need support of internal 
> zend_object_handlers. But that's not a blocker, we might provide some 
> default internal traits with PHP, enabling the internal class handlers.
> So to summarize, I would not continue on that path, but really invest 
> into monomorphizable generic traits instead.

Interesting.  I have no idea why Arnaud has mainly been investigating reified 
generics rather than monomorphized, but a monomorphized trait has potential, I 
suppose.  That naturally leads to the question of whether monomorphized 
interfaces would be possible, and I have no idea there.  (I still hold out hope 
that Levi will take another swing at interface-default-methods.)

Though this still wouldn't be a path to full generics, as you couldn't declare 
the inner type of an object at creation time, only code time.  Still, it sounds 
like an area worth considering.

--Larry Garfield

Reply via email to