Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120839 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64866 invoked from network); 18 Jul 2023 16:41:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jul 2023 16:41:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ECF6F1804C9 for ; Tue, 18 Jul 2023 09:41:44 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 18 Jul 2023 09:41:44 -0700 (PDT) Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-1b773fa5863so1030272fac.1 for ; Tue, 18 Jul 2023 09:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=negyesi-net.20221208.gappssmtp.com; s=20221208; t=1689698503; x=1692290503; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=qmVjohqfmG4KVrmDko2AOdtEnbFaFDM9GWbyMIR9rSI=; b=YxbJidnTmTxZu6Z5Yvc6Eqr3vvfYciuzCAV/FC+HM2PlWRerii5AjQUVXfgx8gjlcS /kaoOKsFGiJw8EMMh1WF4eD1UtgvfVPPVC2UJEPtSlsLz3DWRQevyDjw/1UyTNl+ro+Z RXhCVv7/q8sReSB0ZhVINh6TYcqiJ4pV7+p9C+uwdrpuHtd7VWw1RMbsIeLFW1CVFM5o 3Fp3rBjWj8o4qgddHOI73n2QwvCLL5beIjDrCMY6951dphfP+KmVbMtrF7t30sYhIrmy VkgqU5L0nAGsJHy/E1jsux4QiFtL06Q3GTX/GBvtrOOfHSqu/w4SupyaZ/JXZndLv9+q e0TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689698503; x=1692290503; 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=qmVjohqfmG4KVrmDko2AOdtEnbFaFDM9GWbyMIR9rSI=; b=MjakzpeGFg0gFSaahxtDVh1Q+ig1FjQKJ8XH1n4zexI2oDqwA8vNGLgFpd2ykHATJp uubr8fjNh9dL5gDAgrKMR6hDSIMMFSI7N8st8ECV/y5JFf/qzA023Rvv1yezTjEheyBI jeE3ihK8zg2FOJkqhKs0AjeKdpzb7NKhodniV2Wt4c97pejoo9hL6HTLCTNOOH0+lLSK xNLPUnxz63nBoKEUlm5bq5lLikITBd8KEDNpBq+dQwti0aY3zp7jXBsG0SeTNgrOHm6K 3jJMN+9nprw5GgWpr7nFI5z06KYtKeI0c72uUXFpgdXPYTm50ERnXAOyA85+qF6yAiwi hC5g== X-Gm-Message-State: ABy/qLZz0bwo+e55Sf0KISbABSB/ETaezglg0mmqQBMKBEGjSyKzQhLT 2Xm83zJGaaXIlij4JmKOvJjoFBdC1A18E+uZE/E= X-Google-Smtp-Source: APBJJlFJTEk5CQ2pRvOMrIGWmOsBdeZUpVYcMreUa0WV1co+JRv49b9b4+rX1B3TPYNKKIZuhfRpCg== X-Received: by 2002:a05:6870:f687:b0:1ba:9fd6:dd77 with SMTP id el7-20020a056870f68700b001ba9fd6dd77mr3759604oab.2.1689698503196; Tue, 18 Jul 2023 09:41:43 -0700 (PDT) Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com. [209.85.219.179]) by smtp.gmail.com with ESMTPSA id d1-20020a0ddb01000000b005772b76cb18sm556355ywe.4.2023.07.18.09.41.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 18 Jul 2023 09:41:42 -0700 (PDT) Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-c11e2b31b95so6069710276.3 for ; Tue, 18 Jul 2023 09:41:42 -0700 (PDT) X-Received: by 2002:a25:d7d5:0:b0:c63:7758:701f with SMTP id o204-20020a25d7d5000000b00c637758701fmr139899ybg.65.1689698502424; Tue, 18 Jul 2023 09:41:42 -0700 (PDT) MIME-Version: 1.0 References: <8055b366-32f1-4d2c-85d0-0cf665e6c8d3@app.fastmail.com> In-Reply-To: Date: Tue, 18 Jul 2023 18:41:29 +0200 X-Gmail-Original-Message-ID: Message-ID: To: =?UTF-8?Q?Olle_H=C3=A4rstedt?= Cc: Larry Garfield , php internals Content-Type: multipart/alternative; boundary="00000000000003c0bd0600c59737" Subject: Re: [PHP-DEV] pipes, scalar objects and on? From: karoly@negyesi.net (Karoly Negyesi) --00000000000003c0bd0600c59737 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable So. Let's get back to pipelines. I wrote this email because I was manipulating a robots meta tag string: $robots_array =3D explode(', ', $robots_string); $robots_array =3D array_diff($robots_array, $remove); $robots_string =3D implode(', ', $robots_array); Very pipeline-ish. You could write a userspace pipeline https://gist.github.com/chx/6638aba76d8b414ffedc7e5af78fb479 but this has the advantage of being spectacularly ugly and slow as well. Just converting it into a pipeline with $robots_string |> fn ($x) =3D> explode(', ', $x) |> fn ($x) =3D> array_diff($x, $remove) |> fn ($x) =3D> implode(', ', $x) has the same characteristics. What I would love to see: $robots_string |> explode(', ', $) |> array_diff($, $remove) |> implode(', ', $) While that does look like partial function application, it does not need to be. It could be just syntactic sugar. Namely, in the expression following |> a $ is replaced by the entire expression before the |>. Step by step: explode(', ', $robots_string) |> array_diff($, $remove) |> implode(', ', $) array_diff(explode(', ', $robots_string), $remove) |> implode(', ', $) implode(', ', array_diff(explode(', ', $robots_string), $remove)) We could use any other symbol but I liked the $ sign here because the entire point is not needing a temporary variable between steps so the $ sign stands for "unnamed temporary variable". I also believe it can't lead to any ambiguous situation (famous last words). What do you think of this simple version? On Tue, Jul 18, 2023 at 2:57=E2=80=AFPM Olle H=C3=A4rstedt wrote: > 2023-07-17 21:57 GMT+02:00, Larry Garfield : > > On Mon, Jul 17, 2023, at 7:07 PM, Olle H=C3=A4rstedt wrote: > >> 2023-07-17 18:58 GMT+02:00, Larry Garfield : > >>> On Mon, Jul 17, 2023, at 2:57 PM, Olle H=C3=A4rstedt wrote: > >>>> 2023-07-17 14:25 GMT+02:00, Karoly Negyesi : > >>>>> Hi, > >>>>> > >>>>> I tried to read on why the pipe RFC failed but by and large I also > >>>>> failed. > >>>>> > >>>>> The discussion on https://github.com/php/php-src/pull/7214 is very > >>>>> short. > >>>>> > >>>>> https://externals.io/message/114770 is not so short but it seems no= t > >>>>> to > >>>>> cover the latest version which uses first class functions? > >>>>> > >>>>> Could someone please give me a summary why it failed? I really woul= d > >>>>> like > >>>>> to see it succeed :) I am writing code if not daily but certainly > >>>>> weekly > >>>>> that certainly looks like a pipeline. > >>>> > >>>> The pipe RFC was kinda forced in before a deadline, no? > >>>> > >>>> My own two cents: > >>>> > >>>> * It's trivial to implement a pipe() function or a Pipe class > >>>> * A Pipe class is better than both a function and built-in operator, > >>>> since it can be configured with custom behaviour, e.g. stop or throw > >>>> on empty payload, or repeat on a collection, or even with parallelis= m > >>>> or concurrency > >>>> * If I had voting rights, I'd vote in favor in a pipe operator :) > >>> > >>> From my recollection, there were a couple of things involved. > >>> > >>> 1. It was intended to pair with the PFA RFC, which didn't pass, which > >>> made > >>> it a bit less compelling. > >>> 2. It was close to the RFC deadline, and it seems people get squeamis= h > >>> around that. > >>> 3. Some folks wanted Hack-style pipes instead of the pipes used by > every > >>> other language with pipes. I've written before on why that's a worse > >>> design. > >>> 4. Arguments that it can be done in user space, which is not true, as= I > >>> have > >>> a user-space implementation and it's comparatively cumbersome and > >>> definitely > >>> slower than a native operator would be. > >>> 5. General "meh" attitude on FP features in general from some people. > >>> > >>> Side note to Olle: If you want a customizable pipe, you've just > described > >>> a > >>> Monad. :-) It's literally "contextually-sensitive func concatenation= ." > >>> A > >>> monadic bind operator would be harder to do with PHP's weaker type > >>> system, > >>> but there are ways it could be done. > >> > >> Mm I don't really agree with that, I think monads make sense only in > >> languages which support them syntactically. A Pipe class is a very > >> straight-forward construction, and the blog posts I've read about > >> monads in PHP don't look pretty at all; lots of syntactic noise going > >> on. But that's another discussion... :) > > > > At its most basic: > > > > class Foo { > > public function __construct(public readonly mixed $val) {} > > > > public __bind(callable $c) { > > return $c($this->val); > > } > > } > > > > new Foo('beep') >>=3D func(...); > > > > Where >>=3D is the operator that translates to "Call __bind() on the LH= S > > object with the callable on the RHS." Poof, we now have a monad > operator. > > This one is effectively the same as |> as it doesn't do anything, but y= ou > > can do whatever you want in the __bind() method. > > 1. You also want syntactic sugar around this to "flatten" monadic > usage; in OCaml it's `let*`. > > 2. This way you won't get read-process-write pipelines as first-class > values, which you can do if you just make a Pipe class instead. I > think. Correct me if I'm wrong. :) > > Olle > --00000000000003c0bd0600c59737--