Re:TC39 Pipeline Operator – Hack vs. F#
by abecedarius on Tuesday September 14, 2021 @05:15PM
(#28531366)
If you're inventing a special shorthand for functions like foo(42, ^), then why only in the context of a pipe? Make up some punctuation to introduce or surround this kind of expression, then use it anywhere. Less to learn, more useful.
[ Parent
| on HN ]
This is sort-of how Scala does it. _ in the context of a lambda means "the next argument", so it is general:
val plus: (Int, Int) => Int = _ + _
Re:TC39 Pipeline Operator – Hack vs. F#
by ejones on Tuesday September 14, 2021 @05:39PM
(#28531729)
There's a proposal for this: https://github.com/tc39/proposal-partial-application
Re:TC39 Pipeline Operator – Hack vs. F#
by abecedarius on Tuesday September 14, 2021 @06:31PM
(#28532395)
That's more specialized: it can express
foo(42, ?)
but not what you'd write within this pipe syntax as foo(42, ^) + 1
The tradeoff is that it doesn't need some extra delimiter since the function call is what delimits it. Perhaps that's a better tradeoff, I'm not sure; but for sure we shouldn't have both.
Re:TC39 Pipeline Operator – Hack vs. F#
by jasperry on Tuesday September 14, 2021 @05:31PM
(#28531622)
It looks like Hack doesn't support first-class functions, which would explain why they don't do this. But I agree that it would be a neat short notation for lambdas.
Re:TC39 Pipeline Operator – Hack vs. F#
by throw_m239339 on Tuesday September 14, 2021 @05:26PM
(#28531545)
and why stop there? Introduce lazy evaluation, type classes, custom operator overloading and what not...
I'm jesting of course, I find JavaScript already too complicated, it's like some people want to make it look like Scala... just no.
Re:TC39 Pipeline Operator – Hack vs. F#
by abecedarius on Tuesday September 14, 2021 @06:23PM
(#28532296)
Very reasonable, and that's why I phrased it like "if we do this".
A TC39 member on this topic of restraint and priorities: https://erights.medium.com/the-tragedy-of-the-common-lisp-wh...
I'm mainly puzzled why they want to introduce additional syntax specific for it, when higher order function are perfectly possible in the current language already and integrate well with the F#-style pipe.