Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119681 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11848 invoked from network); 10 Mar 2023 20:17:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Mar 2023 20:17:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7A9C81804AA for ; Fri, 10 Mar 2023 12:17:06 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 10 Mar 2023 12:17:06 -0800 (PST) Received: by mail-yb1-f175.google.com with SMTP id g27so2729353ybe.3 for ; Fri, 10 Mar 2023 12:17:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678479425; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=bMV/jbdZWnWp1dmZGZo3GQKrFJ2dvrzRY5qDrPETaxE=; b=X/f9yZdt67LIlPep58vopoSgVFHdCCN67RUKeIbxHCila1+asxATjR4f+l1OGvTncN ChhuNGEpgKnX+goj897bmk1L0aJov4fEa0oSXpiClbRW38/MXejgUb+AtspPJ57mWleG xmVPmfxEAZjerwqi2QYeAUiFjpHZV+HZrda1nwk2+Sa/vkpP2Cw95WyLOiZeq1vMctiL vXEihF37V1H8TUYZYB0VZTx/AkDKoazbv+ILwWR3B03dZ4+NS8YKWUXVNRQS6XwSshKi Fkp8SXMKczu54lwFSEIzPjFA8NGSmNy5itPmhCNP9OPedRMDreaZFehm/028ezVT9W1P MIZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678479425; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bMV/jbdZWnWp1dmZGZo3GQKrFJ2dvrzRY5qDrPETaxE=; b=BJ7vi9ke5CHQ8yuAZZ6+/KqtN1rKFVhTI5DsuI7ELfo/1f9hWIN+BVCRsV1vkiKF5y y5Wl0oOarEyU7ssTCH7QSc8HiT+4nkMf5cGgo1Q5RvC7UXrOsLq4+809c6H8cKan4Wsn da623ccVfcUVRh/QYOFYTz7x0epCmTFIVCFPukLDUYUmo3c79saQVJX9dJoGWhW11U/I /Xs1MqUTFR4Jj82F05Fh8I1blByZ0OZoTFPn8LY4DIkfnRL+69dI8XxoGwdcdGKWzE1S dTcgpW+MNtshRqmVJIBgX6ZrFh63FLCjHXbnDISTOALrHL+pTKs3bCnDQlj5sdSlHAZO LzQA== X-Gm-Message-State: AO0yUKXbA0UZ4TBf3wCZmx1ivLhfEGOSPG3PGaPdMprG2NbS42V2Vud7 iDAgIzDgPlH22c2jfZDGdz0txTvkmjio5tThPts= X-Google-Smtp-Source: AK7set+tzRrNPMQ78GhcrC/gyiuKbZuXUHGkFfy2YZ/J4fIWYa26cBbwhGcCBWIat48ifBXu6+qW4iOvVyelS3ORsk4= X-Received: by 2002:a5b:7:0:b0:a06:55b5:3cdf with SMTP id a7-20020a5b0007000000b00a0655b53cdfmr13340248ybp.3.1678479425281; Fri, 10 Mar 2023 12:17:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 10 Mar 2023 22:16:57 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000e8234405f69171fd" Subject: Re: [PHP-DEV] First-class callable partial application From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000e8234405f69171fd Content-Type: text/plain; charset="UTF-8" I glanced over this RFC and suggested syntax has question marks. Each one stands for a single parameter. Since there are named arguments already, it seems to be redundant. We'd rather pass couple of named arguments and place the ... construction at the ending than twirl around with question marks in order to describe which parameters final closure will have. When we do PFA, what we think of is what we pass, not what would be necessary to pass afterwards. And yes, any feature should start from the smallest possible form. If we try to implement all at once, we would get nowhere. On Fri, Mar 10, 2023, 9:53 PM Larry Garfield wrote: > On Fri, Mar 10, 2023, at 1:04 PM, Eugene Sidelnyk wrote: > > Hello internals! > > I'm just wondering why First class callable syntax doesn't allow partial > > application? > > Recently I stumbled across following scenario where it could be really > > useful: > > > > ``` > > public function __invoke(SendOtpCommand $command) > > { > > $this->cache->get($command->getPhone(), $this->storeOtp($command, > > ...)); > > } > > > > private function storeOtp(SendOtpCommand $command, ItemInterface > $item) > > { > > // some logic > > } > > ``` > > > > In this example, I supposed that the closure created will accept a single > > parameter $item, and when it is called back, method storeOtp will accept > > both $command and $item. As it turned out to be, it doesn't really work > > this way. > > > > Another simplified example: > > > > ``` > > // partial application > > foo(bar(1, ...)); > > > > function foo(Closure $closure) > > { > > $closure(2); > > } > > > > function bar(int $a, int $b) > > { > > var_dump($a, $b); // 1, 2 > > } > > ``` > > > > Closure in foo accepts only one parameter. But when it is actually > > dispatched, bar is called with two arguments. > > > > Are there any pitfalls, which prevent implementation of this nifty > feature? > > There actually was an RFC for full partial application a few years ago: > > https://wiki.php.net/rfc/partial_function_application > > The main drawback is that in order to work, it had to do some very tricksy > things with very critical parts of the code (how functions get called). > Enough people felt that was too risky for the functionality and it didn't > pass. First-class-callables were deliberately submitted ( > https://wiki.php.net/rfc/first_class_callable_syntax) as a sort of > "junior version" of partial function application that could be done with > far less invasive changes. > > I'd *love* to see some form of PFA make a come-back, either with a simpler > implementation or a reduced scope that allows for a simpler > implementation. I am not aware of anyone actively working on it at the > moment, though. (If anyone is, please speak up!) > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --000000000000e8234405f69171fd--