4 ms·
I'm with you on the currying thing. The ability to curry functions doesn't enable you to do anything you couldn't already do better and with more flexibility b
by tiglionabbit 14y ago
I'm with you on the currying thing. The ability to curry functions doesn't enable you to do anything you couldn't already do better and with more flexibility by writing the full anonymous function.
Their example breaks down the moment your argument order matters: https://gist.github.com/3052264 https://gist.github.com/3052264
- Peaker 14y agoThey 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); }; }; };
- ionfish 14y agoYes, it does. This is true in Haskell too, of course. subtract :: (Int, Int) -> Int subtract (n, m) = n - m fiveMinus = (curry subtract) 5 minusFive = ??? subtract' = \n m -> n - m fiveMinus = \m -> 5 - m minusFive = \m -> m - 5
- tiglionabbit 14y agoYes, what does? Are you agreeing or disagreeing with my statement that currying is useless? I think you're agreeing.