Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114787 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46278 invoked from network); 8 Jun 2021 14:39:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jun 2021 14:39:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA50C1804F4 for ; Tue, 8 Jun 2021 07:53: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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 8 Jun 2021 07:53:53 -0700 (PDT) Received: by mail-lf1-f44.google.com with SMTP id j2so4914397lfg.9 for ; Tue, 08 Jun 2021 07:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=JchdxabvK49YWzKlyAgKP3Gf7FxlVckZ2fRfjH5Hg3E=; b=Sik6tSMfEwKo1ox6GThxKL/R1M4tFWTcz+sXtUprZE/z5ZK0ivye80dMN5fCu+NezH M3MuMEclvx8mIJ7lFob0ABK/9XV2oY6qifO+9uAK5PgORyneDX2jT+39KU9snIgri+Hh 13fBuG5P0WYKNyb3Hx7PlpHIZ+0LO0C8gEMg5ehkb6f2I9nJS1ioQvDF+Kb5BPCmEthn ECsMI6ZpfAOFh70OlBxpG0D9Ze+PKgFBSEz5XCD9ir/pTzxWFNF3FDtkQjfRi+mc4KHy T57tBcb01sRNg29X55FysKzP5ecihRk/gNBlv5b1php/SwdQAum0rA16gy6o8oRG4xa5 5eVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JchdxabvK49YWzKlyAgKP3Gf7FxlVckZ2fRfjH5Hg3E=; b=MQ+hujvm2JgSCUsC2fUTVliK45Krix7cbgTMXLtIyrZU01lu7ffUdcyDaUEvB+anBo 0JhFH754AWHG94DLcVc2JYeZFJVZZ5rL8TVJqNI79VTG06t8bfa0vSCxOjzZQbkgbnhL kmOE8EmlKIqlzHUxamHoRW8RuhJ99Qon60aF4TiisSPLFd1D02oyZPioIJ8ZXOr5NCxA eUQWn7WpJVq3XXpx3qBg3lUQuHT1T8DSsId46L3ZdwnIyrc6Zlsbh5sUClgZm5tEXkus lMPlVWYGyrgwkK2phG9KxA2+GKp8Lo+xbiPc1XrGwpeq/r/IP36W2jiSxbYWLQZWK+tq kKGw== X-Gm-Message-State: AOAM533XyF8r0OpuaWuEWLzYnbpoRklqwsulBfYdk8gE5e99YbormvxC 5Q2dytQI/xjMgo1Wh9JqMNt2mOfIQ1IofXsWnOjLCI06Xw== X-Google-Smtp-Source: ABdhPJxAim6/ca1T5ImidxZh+RR54Svk4CbaVDBfxs+3Ztout/Wmz39Fn04eF3dLB2gh114HRSKSVNQjff0X9ztLq2M= X-Received: by 2002:ac2:508f:: with SMTP id f15mr14747952lfm.119.1623164031879; Tue, 08 Jun 2021 07:53:51 -0700 (PDT) MIME-Version: 1.0 References: <13daea98-c32e-491b-a37c-3e151dd1f6c2@www.fastmail.com> <8a890865-a7e0-49c0-aecd-73576c7d2ab1@www.fastmail.com> In-Reply-To: <8a890865-a7e0-49c0-aecd-73576c7d2ab1@www.fastmail.com> Date: Tue, 8 Jun 2021 16:53:40 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000884e6605c44253c7" Subject: Re: [PHP-DEV] [RFC] Pipe Operator, take 2 From: guilliam.xavier@gmail.com (Guilliam Xavier) --000000000000884e6605c44253c7 Content-Type: text/plain; charset="UTF-8" On Tue, Jun 8, 2021 at 4:09 PM Larry Garfield wrote: > On Tue, Jun 8, 2021, at 5:41 AM, Guilliam Xavier wrote: > > > you forgot to update one > > `explode(?)` to `str_split(?)`, and also, the first `fn($v) => > > 'strtoupper'` should be just `'strtoupper'`. > > I deliberately made that example extra verbose to show how ugly it can > get, but I can shorten it. > Extra verbose would have been `fn($v) => strtoupper($v)`, there was obviously a typo (already correct in the second equivalent code fragment). Anyway, I see you fixed it, and also updated the Haskell section :thumbsup: > > > Also, quoting from > > > https://wiki.php.net/rfc/first_class_callable_syntax#partial_function_application > > : > > > > """ > > Both approaches to the pipe operator have their advantages. The $$ based > > variant allows using more than plain function calls in each pipeline step > > (e.g. you could have $$->getName() as a step, something not possible with > > PFA), and is also trivially free. A PFA-based optimization would entail > > significant overhead relative to simple function calls, unless special > > optimization for the pipe operator usage is introduced (which may not be > > possible, depending on precise semantics). > > """ > > > > Could you (or Nikita) expand a bit on this (esp. the advantages of the > PFA > > approach / disadvantages of Hack's approach)? > > It's true PFA doesn't cover every possible RHS of pipes. In practice, I > think using the piped value as an object on which to invoke a method is the > only major gap. Normally in functional code you would use a lens in that > case, which (if I am understanding those correctly; that's roughly at the > edge of my functional understanding) is essentially a function call that > wraps accessing a property or calling a method so that it feels more > functional, and thus pipes cleanly. > > However, piping with callables has a number of advantages. > > 1) The implementation is vastly simpler. It's simple enough that even I > can manage it, whereas Hack-style would be more considerably implementation > work. > > 2) I would argue it's more flexible. Once you start thinking of > callables/functions in a first class way, producing functions on the fly > that do what you want becomes natural, and fits better with a > pipe-to-callable model. For instance, the comprehension-esque example > (which I suspect will be one of the most common use cases of pipes) is far > cleaner with a callable, as it can obviate any question about parameter > order. > > Another example I threw together last night is this proof of concept last > night, which works when pipes, enums, and partials are combined. I don't > think Hack-style would be capable of this, at least not as elegantly. > > https://gist.github.com/Crell/e484bb27372e7bc93516331a15069f97 > > (That's essentially a "naked either monad".) > > 3) I disagree that the overhead of arbitrary callables is "significant." > It's there, but at that point you're talking about optimizing function call > counts, mostly on partials; unless you're using pipes for absolutely > everything, go remove an SQL query or two and you'll get a bigger > performance boost. > > 4) Far more languages have callable pipes. Hack is, as far as I am aware, > entirely alone in having pipes be combined with a custom expression syntax > rather than just using functions/callables. That isn't conclusive proof of > anything, but it's certainly suggestive. > > I'm going to be moving forward with this approach one way or another (if > for point 1 if nothing else). I do believe it is the more flexible, more > robust approach, and fits with the general strategy I recommend of small, > targeted changes that combine with other small, targeted changes to offer > more functionality than either of them alone. That's exactly what we're > doing here. > All good points IMHO. Thanks! -- Guilliam Xavier --000000000000884e6605c44253c7--