just => fucking => use => “them”;
Is equivalent to:
function (just) {
return function (fucking) {
return function (use) {
return “them”;
}
}
}
just => fucking => use => “them”;
Is equivalent to:
function (just) {
return function (fucking) {
return function (use) {
return “them”;
}
}
}
Haskell has an arrow notation language extension, which is a kind of syntactic sugar for function composition. Ordinarily you can use the dot (.) operator to compose functions from right to left, and the (>>>) operator is (.) with parameters flipped, so you can write:
(+ 1) >>> (* 3) >>> print
which would create a function equal to:
x -> print ((x+1)*3)
But this seems to be different from how JavaScript arrows work.
LikeLike
“Although the arrow in an arrow function is not an operator, arrow functions have special parsing rules that interact differently with operator precedence compared to regular functions.”
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
LikeLike
Then again, I never liked the function statement shortcut either. I always use explicit lambda forms.
developer.mozilla.org – Arrow functions
LikeLike
Ramin Honary this looks a lot like the type signatures in Haskel. The main thing is that it is a curried function which creates closures to enable access to the earlier args.
LikeLike
mathew murphy I’m not seeing a downside. The best part is no bindings to this or arguments.
LikeLike
John Hardy not a Turnbull fan Oh, I get it. In Haskell, all functions are curried by default. So JavaScript had it’s syntax expanded to allow you to define curried functions.
So the example they gave appears to be what is called an “Endofunctor”:
const composeMixins =
(…mixins) =>
( instance={},
mix = (…fns) => x =>
fns.reduce(
((acc, fn) => fn(ac)),
x
)
) =>
mix(…mixins)(instance);
translated to Haskell would probably be something like:
composeMixins = mixins ->
let instance = mempty
mix = fns -> x ->
foldr ($) x fns
in mix mixins instance
where ($) is the application function, which is equivalent to JavaScript
((acc, fn) => fn(acc))
And, just FYI, the Haskell equivalent I wrote up above could be further simplified to this:
composeMixins =
foldr ($) mempty
LikeLike
That’s clever stuff. Consider me 5% along the path of understanding this shit.
Have you looked at PureScript? Seems Haskelish. I couldn’t understand much from their home page.
LikeLike