Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119687 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39564 invoked from network); 13 Mar 2023 18:45:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Mar 2023 18:45:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 11C381804F7 for ; Mon, 13 Mar 2023 11:45:01 -0700 (PDT) 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, 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-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (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 ; Mon, 13 Mar 2023 11:45:00 -0700 (PDT) Received: by mail-yb1-f179.google.com with SMTP id e71so4594049ybc.0 for ; Mon, 13 Mar 2023 11:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678733100; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=flZcpGXi+AF/uejg1xzs325CejF+BOMvbyQ5zZw9bXU=; b=dBVtCTZAHQI4IWTraXcNOLtepCKKOEjpRNJmdKBxS2hQUuTi4QtCE0WvNRk/yGR6Vj 2/2CbHeuYwJOGIOxW1z2R74PImtHTu4qI5D5+81b6LV62Kgoaw7XfrEmrmTB6Bc0ZX1R 3mn/ZAd4Bhf0LoYqGvlpDLv4lcKD7Hu/Y+AdU4rqhX/TYKe/hsHAYZQfx0K+dvjtNeyV 3yFF7WcjfFOQi1lh9+xVtAzeFh2y2QTVCDG5NnjgAUO9jQM1doJ3OzWRwyeyzx35gnIC obfE3pTPUS3NwAAyN/t9EKxD1g4UFPaUcBN+NwF2YwZ4xUsQSbJl6hUuItI5TEVCG5i4 9Irg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678733100; h=content-transfer-encoding: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=flZcpGXi+AF/uejg1xzs325CejF+BOMvbyQ5zZw9bXU=; b=IAiTBn/7kONK7aZHFUmxRPRbRtF+09jK7GGPaaJpAVN1szfm6bobJyG5kmLII2XMg0 Rx42tfaVdAuyOBs5AWGYy9EPXVWY2Oa+syRMn/xpOxc5SSayGWfTUp2xzEEyyu1ZHYfa 2hpdjXgE0ZVxFIrrbp/b9xGLDasKVpR/ZHrDJHf+o/1NH+jJ+m1Qez1KHQrc3YTlTGRD ErQukeEIjKbwBGXKf8axmV78dpWpJfreMiVu0tD9D+Dol+ztUwxI+J8Ip7eHYo+gMCqZ yURd/aayJlnkscKGEUStpKaEGbMH8tlxNlgRB+adkrYdLaBGvDZrwTPLVdn24ceC3nJT xuCQ== X-Gm-Message-State: AO0yUKVDsNQBwx5exBUf/mzx+3rrFnVyhGEqD/J/FgNfkmw3OKrGNe4a S6FwU0sGQBJyKdSo4aEwFuNwh3MbiCPu0kbnaOU= X-Google-Smtp-Source: AK7set9l850eZJy/Nf9xkjdrReLCjxoPvArRGn8q/Y9HVAO9FRfsblDwhIItQQvlF7Dceqqp4Rm1NWGDg/34LkRDAUM= X-Received: by 2002:a5b:688:0:b0:aa9:bd2e:3744 with SMTP id j8-20020a5b0688000000b00aa9bd2e3744mr17383686ybq.9.1678733099873; Mon, 13 Mar 2023 11:44:59 -0700 (PDT) MIME-Version: 1.0 References: <9975B833-EE24-4ED7-B28E-841B92988BA0@cschneid.com> In-Reply-To: Date: Mon, 13 Mar 2023 19:44:48 +0100 Message-ID: To: Rowan Tommins Cc: PHP Internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] First-class callable partial application From: landers.robert@gmail.com (Robert Landers) On Mon, Mar 13, 2023 at 12:28=E2=80=AFPM Rowan Tommins wrote: > > Hi all, > > On Sat, 11 Mar 2023 at 22:48, Robert Landers > wrote: > > > My "syntax sugar" implementation was that this: > > > > return $this->cache->get($command->getPhone(), $this->storeOtp($command= , > > ...)); > > > > gets turned into this: > > > > return fn(...$x) =3D> $this-cache->get($command->getPhone(), > > $this->storeOtp($command, ...$x)); > > > > There were a number of edge cases to solve, but I stopped > > implementation before I got there. > > > > > As someone who voted for the RFC a couple of years ago, and was > disappointed it didn't pass, I'm pleased to see more interest in this. > > It's worth noting that the previous implementation was reached after a lo= t > of different experiments, and there were a few requirements that guided i= t, > including (in no particular order, and I've probably forgotten something)= : > > * Placeholders need to be possible for any parameter, not just > left-to-right; e.g. it must be possible to apply the callback parameter t= o > array_filter (which is the 2nd param), producing a callable that accepts = an > array to filter > * It should not be possible to partially apply a non-existent function; > this is one of the big advantages of first-class callable syntax over > existing string-based callables: https://3v4l.org/Vr9oq#v8.2.3 > * Errors from passing incorrect parameters should show as an error in the > actual call, not the wrapper; compare existing FCC behaviour with a manua= l > lambda: https://3v4l.org/Q2H2Z#v8.2.3 > * The generated callable should have correct parameter type and name > information visible in reflection (closely related to previous point) > * The relationship with named parameters and variadics needs to at least = be > well-defined, even if it's "error with a possibility of expanding > functionality later" (this caused a lot of pain in some of the > implementation ideas) > * Repeated partial application (currying and similar) should ideally not > result in a whole stack of wrappers; that is $f =3D foo(42, ?, ?); $g =3D > $f(69, ?); should result in the same object as $g =3D foo(42, 69, ?); > > This is definitely one of those features where "the devil is in the > details", and a simpler implementation is possible, but may not be > desirable. > > Regards, > -- > Rowan Tommins > [IMSoP] Hey Rowan, > This is definitely one of those features where "the devil is in the > details", and a simpler implementation is possible, but may not be > desirable. My approach was more of an iterative one. 1. Get left-right done so that $x =3D something($left, $right, ...); would be allowed, but not $x =3D something($left, ..., $right); This would bring some immediate benefits, as initially proposed. I'd also propose that variadic arguments wouldn't be allowed, thus array_map(..., $x); would be allowed, but not array_map($callback, ...); 2. Implement middle/variadic arguments I felt that this could be it's own RFC once the above is implemented. As you said, the devil is in the details... what does array_map($callback, ..., $right) do? Is the partial application variadic? These are things that I felt couldn't realistically be answered until we saw some real-life usage and feedback from (1) above. 3. Optimizations This would be when we flatten the callback chain OR maybe by now, the genius(es) working on the opcache would have already beaten everyone to the punch.