On Sun, Jun 30, 2024, at 18:13, Michał Marcin Brzuchalski wrote: > Hi Richard, > > czw., 27 cze 2024, 22:33 użytkownik Richard Miles <richard@miles.systems> > napisał: >> >> > I worked with Joe Watkins to do a proof-of-concept for generic traits. >> > It's a bit old since it's from 2017, but could be a useful starting >> > point if you are serious about pursuing this idea: >> > >> > https://github.com/php/php-src/compare/master...morrisonlevi:php-src:parameterized_traits >> >> >> I’m also interested in this; it will help see branches like these. >> Did you ever get the POC working? What did you feel like was the biggest >> hurdle? > > There even was an RFC in voting which Joe implemented and it addresses nearly > what is discussed it this thread https://wiki.php.net/rfc/arrayof > > I must admit that the collection<Dict> proposal is bit too complex to address > such tiny but powerfully in my opinion functionality which is typed array. > What Derick showed looks more like generic collection and such require > declaring it's type. In my opinion this is way too mush hassle to declare as > many collection types as many usages in application. Also two collection > types with the same collection item type will not be compatible from type > perspective. While typed array seems much more clear and compatible in all > places where typed array is needed without declaring separate type for each > usage. > > If I were to choose between typed-array and collection like Derick showed a > little bit I'd choose typed arrays definitely as a first feature to be merged > into PHP. > > Cheers, > Michał Marcin Brzuchalski >>
Hello again, I’ve been thinking about this off-and-on. One of the issues brought up in this thread around type-checking arrays is their unboundedness, and the performance implications of that. Instead of typed arrays, why not start with typed Tuples? Tuples are nice because they are bounded, they can probably act like arrays (possibly even cast to them and vice-versa). I’m imagining something like (to borrow from another RFC): function bcdivmod(…): Tuple<int, int> which can be destructured just like an array. From the perspective of userland, they are bounded, typed arrays. — Rob