Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120833 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41127 invoked from network); 18 Jul 2023 12:57:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jul 2023 12:57:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 023611804B0 for ; Tue, 18 Jul 2023 05:57:21 -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-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (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 05:57:20 -0700 (PDT) Received: by mail-il1-f179.google.com with SMTP id e9e14a558f8ab-345e55a62d8so25718925ab.3 for ; Tue, 18 Jul 2023 05:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689685040; x=1690289840; h=content-transfer-encoding:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uWl0+2gVKJxWhAEOIL55g3X7Xh2u5oF1ubOyaFWS8YM=; b=VCpmisBOAca2JvMKbpa+0Hw6RyxRbuWGZG14SKE8qbU6p6W8eVDXU5qdClvzeToWhp 2hBCTtz4hamn3AWQQeG7/jyybP/TIJpormeEVvyuAWY6GV0bh+e1jn9jC4V2NjJnygqW Mr1aAsBtfvCUZ2hL93zEyzRLjneRxQAnkKoJ4D2vW8eiyXS1BUnwdcjAizXfzVc7SbPn BfsP8hELDDklvtlgV58r5hFV5FR4nKbEoAl0VsnLlP/5QzpEw/B/3Ukvv4Pxqz6uui8U uqaNwZLNyQkwqlqZiLs7jcHGeT0M5Mou+MjT7/Pz5prvuMgcoU2OEksseYNc5Khe1MbT 9XIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689685040; x=1690289840; h=content-transfer-encoding:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uWl0+2gVKJxWhAEOIL55g3X7Xh2u5oF1ubOyaFWS8YM=; b=lavixXC8cfL8+bnmk2l3E5llwnzA+LPHh/+RxriAMCWrodAKvJ33aZPxwUotRfSvYb M4TprxAY/iM5WJLA0GMPJ3BVK0j2X0vMWd+APqm+HHeuO3YRgEQWlJzMN1Fhcg6C+joz NsHGu4SXo2lzem6GtoC0FZtdkVq7xCG3u69gVjDaPohSBFKZDsylJe/YRnc3vrsauQsn 7kUjqVY3BNgoaXXoO7HHjX6VDFybWxs648cEedmci47iHNiCMfbqJhj2FErToJUGOR8J EyLrvWgS8Il3FJW1pBHAR9UQIbr07L/4K52Ot5cdQWgxwDP4VFD6gT2ohWQc9vnzj3f/ T+YQ== X-Gm-Message-State: ABy/qLb9lAlOK83iE0hvqiYC+bXaON+VQW4ZaoPUT/wsajIP1efYxvau itZYDqYuQWlJ/qcuW3iJaDcQQgHgqnCd4E5rbPc= X-Google-Smtp-Source: APBJJlGhDtvrfKGJIS4GTIfg96GatAuMSAFFiLIf2bwJpOPNX5D8i8f9FQMuXOM7UB0Oh8yRS+zv9q7gHRIMYaF+zr0= X-Received: by 2002:a05:6e02:190f:b0:345:a201:82b7 with SMTP id w15-20020a056e02190f00b00345a20182b7mr2434145ilu.26.1689685039916; Tue, 18 Jul 2023 05:57:19 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ad5:4204:0:b0:2e2:2af1:79d7 with HTTP; Tue, 18 Jul 2023 05:57:19 -0700 (PDT) In-Reply-To: References: <8055b366-32f1-4d2c-85d0-0cf665e6c8d3@app.fastmail.com> Date: Tue, 18 Jul 2023 14:57:19 +0200 Message-ID: To: Larry Garfield Cc: Karoly Negyesi , php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] pipes, scalar objects and on? From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) 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 not >>>>> to >>>>> cover the latest version which uses first class functions? >>>>> >>>>> Could someone please give me a summary why it failed? I really would >>>>> 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 parallelism >>>> 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 squeamish >>> around that. >>> 3. Some folks wanted Hack-style pipes instead of the pipes used by ever= y >>> 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 describ= ed >>> 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 LHS > 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 you > 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