Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92656 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11384 invoked from network); 23 Apr 2016 12:35:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Apr 2016 12:35:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.194 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.217.194 mail-lb0-f194.google.com Received: from [209.85.217.194] ([209.85.217.194:33658] helo=mail-lb0-f194.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4C/80-07837-A0C6B175 for ; Sat, 23 Apr 2016 08:35:23 -0400 Received: by mail-lb0-f194.google.com with SMTP id ot1so7119708lbb.0 for ; Sat, 23 Apr 2016 05:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=J8TVkQe9hguNPlvpiOlZKSGkH6GxphuMb66fgKvUHt0=; b=m6DYyn0gPvjXPMQpBH7TEjlpmlBz5Gb0O0rLxj/rNwSFEx2+u4uFV18DtZyJwLUOiw MOAqcwhKNcvT9JMey+D82bsI8fQSZDprzV+mybBYPXGxs9iukUlKM5leFkJene4kDJit 6KFjm9oz+4So2DvjkDGk0PIN5wX/rkyvX+IfM3Y1ks3V46nJ5Hn9m23JILK05hXrfaQz bHJu8Afdqm/JW1pjGHJQZDZWuv+N+FJfB0+Sk9sx4aRovWSBm0R19jfEWXDVEkOqcQ6K PyeI/dvCboCQRN/t4BArJIHPV27B1I4bDAJBEsmw/JycF/E1tB6Vm5AywIJxsiocjCOh QnWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:subject:references:date:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=J8TVkQe9hguNPlvpiOlZKSGkH6GxphuMb66fgKvUHt0=; b=GyVO0WHTp6lzQLtfyXow0yyMfnLkfIJDB+GysVbNgAiDzTz/RQOrPRw5muYg6pmEd+ GblQ3KHjpz5wlH18ENkY2YMwdkYvJA7I3EQSwk8XKThv7/OOV3ZyT1yjyLsdY4UXEwQJ oFu3yljLGqDyATVeB6lt28KBItgd56XOhubiWwuqsekrPMopAm2LTSsLQibnM4pUkusl oJNb1PuXStf6jBuaFzHv6tBVQ+U4xd/Q5o0E3Fl7C3VHVRewOzspg2HX7B0JGMW93pX+ hZhKpfrWu4e0sjyL1lTyf9GWjX5hXFqVADKlmdFB6rvUrIEvl3Pp+WjAWB2HzUfhjVct vOrg== X-Gm-Message-State: AOPr4FWs4FlhtrDpS749fp3hioDHZnVgRbCyw5j1ObdB9xwwxSbQa9qPc8KH1sBQzGyhTA== X-Received: by 10.112.34.161 with SMTP id a1mr10720934lbj.29.1461414919104; Sat, 23 Apr 2016 05:35:19 -0700 (PDT) Received: from nikita-pc ([89.250.5.98]) by smtp.gmail.com with ESMTPSA id v72sm2550552lfd.24.2016.04.23.05.35.17 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 23 Apr 2016 05:35:18 -0700 (PDT) Content-Type: text/plain; charset=koi8-r; format=flowed; delsp=yes To: "Dan Ackroyd" Cc: "PHP internals" References: Date: Sat, 23 Apr 2016 15:35:26 +0300 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: User-Agent: Opera Mail/12.17 (Win32) Subject: Re: [PHP-DEV][RFC] Callable Types From: inefedor@gmail.com ("Nikita Nefedov") On Sat, 23 Apr 2016 14:18:56 +0300, Dan Ackroyd wrote: > On 22 April 2016 at 05:12, Marcio Almada 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.