1

I'm trying to implement a recursive container-like structure, and I can understand why a vanilla cyclic typedef would be impossible to realize, but why is the following disallowed as well?

typedef cycle = shape('cycle' => ?cycle); // Cyclic typedef (Typing[4014])

Creating one seems easy enough:

$cycle = shape('cycle'=>shape('cycle'=> /* shape(... =>*/ null /* ...) */));

And iterating through one should pose no problem either, right?

function recurse(cycle $cycle) {
    if(!is_null($cycle['cycle'])) recurse($cycle['cycle']));
}
concat
  • 3,107
  • 16
  • 30

2 Answers2

2

To give a little more colour to the feature request you mention. As far as I know, there's no fundamental reason shapes couldn't work like you suggest. It would even be useful in some cases. It's entirely an implementation problem -- at least as of when I last was familiar with the typechecker code, it actually would have been fairly difficult to implement. (Again, not for any interesting reason, just that the code was written with deep assumptions about how shapes could be expanded out.) That said, shapes have changed somewhat in the intervening year or so since I last looked at this, and it might be easier now, I don't know. But it the feature was never quite important enough to be worth the effort to build out -- maybe it is now or will be soon with the aforementioned shape updates now that they are in somewhat wider use (at FB especially).

Josh Watzman
  • 7,060
  • 1
  • 18
  • 26
0

It's currently a feature-request on facebook/hhvm since last year.

concat
  • 3,107
  • 16
  • 30