Function composition syntax
isiahmeadows at gmail.com
Thu Sep 29 02:19:39 UTC 2016
On Wed, Sep 7, 2016, 10:44 Bergi <a.d.bergi at web.de> wrote:
> interesting proposal!
> > Here's what I propose: a new infix operator `>=>` (operator and direction
> > can change) for composing two functions.
> Sweet, reminds me of Kleisli composition in Haskell
> (which does something different to functions though).
That was an inspiration, but that adds to the list of reasons why I would
be okay with a different operator.
> > 2. It allows engines to statically optimize functions in the middle
> > an extra function allocation), like with `f >=> x => console.log("x:" +
> I don't understand that one. Wouldn't `x => console.log("x:" + f(x))` be
> optimised better (and also be easier to read)?
Yes, but it was a trivial example just for the sake of example.
> > 3. It can simplify the internal model some to deal with a binary pair
> > of an array, especially when pipelining gets involved.
> > 4. Composition isn't usually combined as a function in JS.
> Can you clarify what you mean with this?
Things like `compose(compose, compose)` aren't frequently used in JS
(unlike Haskell's `(.) . (.)`). I almost included that example, but I
couldn't get a wording I liked.
> My questions would be
> * What precedence would the operator have? Clearly something between
> member access and assignment, but what exactly?
> Particularly interesting cases:
> f >=> g (x)
> f >=> p ? g : h
> f >=> x => x >=> g
I intentionally left precedence out (other than implying it's chainable
left to right), to avoid complicating the initial presentation.
* Do we also need a partial application operator to make this syntax useful?
> I guess the discussions from
> https://github.com/tc39/proposal-bind-operator/issues/35 and
> https://github.com/tc39/proposal-bind-operator/issues/26 are relevant
It would help, but no, that's not required. Arrow functions can help in the
meantime, and may be more readable, and sometimes required, in some cases,
since it's more explicit.
(It's come up before, independently:
> Kind regards,
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss