On Fri, 5 Apr 2019 at 12:42, Robert Hickman <robehick...@gmail.com> wrote:
> In the first case: > > function foo(callable $bar): int { return $bar(); } > > I think the value of $bar would have to fall into a set of values > known to the programmer, or at least known at some level. I think you're misunderstanding the problem: it's not that the *programmer* doesn't know the types, it's that the *analysis tool* doesn't know them, because the programmer hasn't told it, and currently has no way to tell it. To be confident the code was type safe, it would have to look like this: function foo(callable<void, int>): int { return $bar(); } ...and every call to it would have to be analysable back to a function explicitly declared as returning int. The same applies to exception checking: you'd need syntax for "accept any callable that never throws", or "any callable that only throws descendants of FooException or BarException". Then you end up with this kind of fun: function curryish(callable<(int, float): int throws FooException|BarException> $callback): callable<(float): int throws FooException|BarException> { return fn($x) => $callback(42, $x); } Regards, -- Rowan Collins [IMSoP]