I don't like curry. Help me reverse the effects of this evil question - Make me some curry - by uncurrying functions.
Task
- Given a blackbox curried function, output its uncurried equivalent.
- The curried function will take a single argument and output either another curried function or a value of another type.
- The uncurried function you create will take the same number of arguments as the curried function, but all at once.
Rules
- In languages without first-class functions, you can use an object with a method in place of a curried function - but please specify this.
- The curried function may also output a function pointer instead.
- If your language does not allow function pointers or makes passing around functions hard to work with, but allows evaluating strings to make functions (e.g. APL), you can use strings to represent both curried functions and your uncurried output function.
- You can also take the number of arguments of the functions as an input to help you determine the depth of currying.
- You may choose to return a function that takes a tuple, list, or other single value containing all the arguments.
- You may constrain the arguments and return type to a data type of your choosing, but that type should have more than 1 possible value.
- If
f
is the inputted curried function andg
is your uncurried function,f(a1)(a2)...(aN)
must always equalg(a1, a2, ..., aN)
. - The order of arguments in the uncurried function should be the same as in the original curried function.
For example, given the function a -> b -> c -> a + b + c
, you can return a function that looks like (a, b, c) -> a + b + c
or arr -> arr[0] + arr[1] + arr[2] -> ...
but not (c, b, a) -> ...
(wrong order). If you also take the number of arguments of the function as input, then (a, b) -> c -> ...
would be an acceptable output given the input 2 (2 arguments are curried).
Bounty
Since Rust is the language of the month, I will be offering a 50 rep bounty on Rust answer to this question if you haven't used Rust before.
id :: a -> a
can be also be called at the typeid :: (a -> b) -> a -> b
. Doesid
have one argument or two (or three or four or...)? \$\endgroup\$.curry
is not what the question means by a curried proc.) \$\endgroup\$a -> a
? Or would it be((a -> b -> c), a, b) -> c
? Or((a -> b -> c -> d), a, b, c) -> d
, or...? But okay, if I can expect the caller to specify the number of arguments, then the goal is more clear. \$\endgroup\$