I'm trying to figure out the cause and effect logics behind "Currying" and comes to the following results:
- Multiple arguments function can be expressed as either tuple(combining multiple arguments with different types as one argument) and list(combining multiple arguments with the same type as one argument). So all functions can be expressed as single argument function.
- So in Haskell, function only takes one argument。How can we implementing multiple-arguments function.
- Using Currying. Currying is a way to implementing multiple arguemnts function.
I think the above logic 1 -> 2 -> 3 is confusing to answer "why using currying". For statement 3, one can also combine multiple tuples or lists as single argument to implementing multiple arguments function.
It seems statement 1 is not correct reason for statement 2. What I'm sure is 2->3 is correct reasoning, but what's the reason behind 2? Why Haskell, as a functional language, only take one argument?
Most books take statement 2 as an accepted fact. Does anybody know the reason behind 2? Or does anybody know the correct logic behind "why currying"?
Bool
has two inhabitants,Maybe Bool
has three inhabitants,(Bool, Maybe Bool)
has six inhabitants), then function types are exponents. Sincee^(x * y) = (e^x)^y
, you can always rewrite a function with type(x, y) -> e
to a similar function with typey -> (x -> e)
. This is currying in a nutshell. Because you can always rewrite such functions (in this case, at a relatively low cost), you don't need to make multi-parameter functions a fundamental concept, which otherwise would complicate your language definition. - user824425