Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119685 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18494 invoked from network); 13 Mar 2023 11:27:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Mar 2023 11:27:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A0B4E180538 for ; Mon, 13 Mar 2023 04:27:53 -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,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-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 04:27:53 -0700 (PDT) Received: by mail-wr1-f46.google.com with SMTP id r18so10973997wrx.1 for ; Mon, 13 Mar 2023 04:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678706872; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=ze2AMEapNqQt8ul8RYnXwmtE7PzBLVI9wiPv/NcROb4=; b=epvPI94ZHi+5ou8dWuTeGMMOnaSpsAJHnXVoG3lorVhEw+5BkB9ep2NtLSNrYS48Vf Wg0lQi58DPsXn7I6jc6CBcfSOdNwfNUjHousg3gl0ffaoOSIa+dEG1QIIWjBlU9PG+VN 6GxAzMa9KT+UDyQIL7/Pxf1xzq8Bm0+mcFxuUg4VlB7qTX+hKGvRGV/Xxne5Ede3Suny eDKXuk0dyVaMnh0DdQRnLJ7rT94aIGGMesHocbjlAtdhhGTpPOIgFOK9fEmbwiZgjsfQ 2eHFuHb/kYOEklk7lreqRxeSrHNn+FVWsoiW7TIjcHCzgKnLgW3QR2T+W98i8MYY5Z3f JjCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678706872; h=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=ze2AMEapNqQt8ul8RYnXwmtE7PzBLVI9wiPv/NcROb4=; b=qFqkq6pvHezEBCx8ybA0xAeQvNWDXdck6gGBvneeztclhVBFF8u7atMGwlm41VhlSj wYikW2LxRAHXKQLO1JtSGieyuQscUQqiSzGT5IiwW09lFP78GWYkNrKEeEmbTbr5DeNK TdZaz9wyvzHflgr6v94AFouJdZ8OGpqhhrsd0zFEprFW8LXeMBGSNErzMP6vljjyRWYu +Po9EpdL6bsZPfOKUtfVWwopNI4NRIFPfX45XQzn5/yPYQgG/Ge/ZljW5KVMq5L1obDH ByviVpKVMp/Pu2S/j4M+RYKWE/a7nTWuGGEIAD3ehtQXRZRnHlJn3sudI8TtJ8s8C6Sa BOcQ== X-Gm-Message-State: AO0yUKV1ltoTiVbfV70SecJBshrAr+MFAKMkkqOx7PBn0pqL6/FsSSJ9 Uu5QY6nsxaseCaogZx8R4gtF+dtmBYToQtoIHd/7AG/tjn4= X-Google-Smtp-Source: AK7set+LrjAbPf8z/ha2ZQmAhDtGghPi8nyjXspWdinVIlZqm5Swloz3KTuRh5J3nwOzWA9wOb5WutZ4oDCG4IH7wZs= X-Received: by 2002:adf:fe85:0:b0:2ce:aa6e:701d with SMTP id l5-20020adffe85000000b002ceaa6e701dmr631662wrr.6.1678706871734; Mon, 13 Mar 2023 04:27:51 -0700 (PDT) MIME-Version: 1.0 References: <9975B833-EE24-4ED7-B28E-841B92988BA0@cschneid.com> In-Reply-To: Date: Mon, 13 Mar 2023 11:27:39 +0000 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary="000000000000c5964005f6c666f8" Subject: Re: [PHP-DEV] First-class callable partial application From: rowan.collins@gmail.com (Rowan Tommins) --000000000000c5964005f6c666f8 Content-Type: text/plain; charset="UTF-8" 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) => $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 lot of different experiments, and there were a few requirements that guided it, 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 to 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 manual 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 = foo(42, ?, ?); $g = $f(69, ?); should result in the same object as $g = 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] --000000000000c5964005f6c666f8--