by tiglionabbit · 14y ago · 0 comments
Their example breaks down the moment your argument order matters: https://gist.github.com/3052264
// 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) Udon.flip = function(f) {
return function(x) {
if(arguments.length > 1) {
return f(arguments[1])(x);
}
return function(y) {
return f(y)(x);
};
};
}; (a, b) -> c
representation. If the uniform/canonical way to use functions is defined to be curried, then flip can simply return them curried.Which it does:
curry :: ((a, b) -> c) -> a -> b -> c
uncurry :: (a -> b -> c) -> (a, b) -> c 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