On Sat, 23 Apr 2016 14:18:56 +0300, Dan Ackroyd <dan...@basereality.com> wrote:

On 22 April 2016 at 05:12, Marcio Almada <marcio.w...@gmail.com> wrote:
Hello everyone,

We just completed the draft for the "Callable Types" RFC.

There seems to be one thing missing from the RFC; please could you add
an example where the parameter and return types are also 'typed'
callables?

Presumably it would look something like this?

function reduce(int $a, int $b, callable(int, callable(int, int):int
$math):int $reducer): callable(int, int):int {
  return $reducer($a, $b);
}

Are there any limits to how far down the callable type can be defined ?

cheers
Dan

Hey Dan,

thanks for reviewing.

I have just added a paragraph about nested callables, I'll copy paste it here:

Nested callables can be used with no imposed limit on the nesting level.

    function foo(callable(callable(int)) $cb) {
        $cb(function (int $i) {
            var_dump($i);
        });
    }

    foo(function (callable(int) $intPrinter) {
        $intPrinter(123);
    });

There's currently no way to reference callable signature from within itself, meaning there's no way to make recursive signatures like below:

function bar(callable(int $number): callable(int $number): callable(int $number): parent_callable $recursiveCb) { // this wouldn't work currently
    }

To add to that, nested callables can get pretty unreadable quickly, both of these problems would be best solved by a typedef feature of some kind, added to PHP later.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to