Re: [RFC] Function pipe operator
| From: | Guilliam Xavier | Date: | Wed, 22 Apr 2020 08:25:50 +0000 |
| Subject: | Re: [RFC] Function pipe operator | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109768@lists.php.net to get a copy of this message | ||
On Tue, Apr 21, 2020 at 4:44 PM Larry Garfield <larry@garfieldtech.com> wrote:
>
> On Mon, Apr 20, 2020, at 11:20 PM, Stanislav Malyshev wrote:
> > Just a small pedantry note - in a comparison section, the RFC compares
> > this syntax to function composition. But this is not function
> > composition. This is a syntax sugar for calling two functions one after
> > another, not operator that produces a function. It sounds pedantic but
> > it's rather important distinction - if |> is composition, than $foo |>
> > $bar is a new callable provided $foo and $bar are callable (but no
> > function is actually being called here!). If |> is call syntax, it's
> > actually the result of calling $bar($foo).
> >
> > So comparing it to function composition is a bit confusing. Otherwise it
> > looks OK to me, except the syntax for calling functions and methods is a
> > bit awkward, but it's not the problem of this RFC I imagine.
>
> I'm not sure I follow. The only place composition is mentioned is in the F# section,
> where it calls out specifically that we're implementing "pipe forward" and *not* the
> composition operators ( >> ). Is that unclear?
Actually it's also mentioned in the Haskell section, but as "function
concatenation" (which adds to the confusion I guess).
Speaking of Haskell, that reminded me of
http://learnyouahaskell.com/a-fistful-of-monads#walk-the-line
where
the author defines a custom
-: operator such that x -: f desugars
to f x (equivalent to how $x |> $f would desugar to $f($x)
with
the RFC), which allows to write e.g. xs -: sort -: reverse instead
of reverse (sort xs) or (reverse . sort) xs.
--
Guilliam Xavier