3 ms·
They seem to simply be missing flip. // Lets curry subtract instead of add var subtract = Udon.curry(function(a, b) { return a - b; }); var five
by Peaker 14y ago
They seem to simply be missing flip.
// Lets curry subtract instead of add
var subtract = Udon.curry(function(a, b) {
return a - b;
});
var five_minus = subtract(5);
var minus_five = Udon.flip(subtract)(5)
- ionfish 14y agoYes, although there is one subtlety here: should `flip` return a curried function, or an uncurried function? This isn't an issue in Haskell since it only has unary functions.
- Peaker 14y agoHaskell has tuples, so it could use an: (a, b) -> c representation. If the uniform/canonical way to use functions is defined to be curried, then flip can simply return them curried.
- masklinn 14y ago> Haskell has tuples, so it could use an: Which it does: curry :: ((a, b) -> c) -> a -> b -> c uncurry :: (a -> b -> c) -> (a, b) -> c
- walrus 14y agoHow about both? Udon.flip = function(f) { return function(x) { if(arguments.length > 1) { return f(arguments[1])(x); } return function(y) { return f(y)(x); }; }; };