Hacker News new | ask | show | jobs
by ionfish 5099 days ago
Yes, 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.
2 comments

How 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);
          };
      };
  };
Haskell 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.
> 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