开发者

Currying is just "optional parameters"?

开发者 https://www.devze.com 2023-02-11 09:44 出处:网络
I read a guy\'s statement on the web saying \"currying is just a fancy way of having optional parameters\". By gut, I feel that the statement is shallow and wrong but I can\'t really put my finger on

I read a guy's statement on the web saying "currying is just a fancy way of having optional parameters". By gut, I feel that the statement is shallow and wrong but I can't really put my finger on it, probably because I don't have enough knowledge on lambda calculus.

When I try to explain the difference my explanation spans paragraphs, mostly com开发者_运维百科ing down to "Currying is having all variations of a function's declaration with less number of parameters as types. But you cannot have all combinations of a function with optional parameters as valid types and use them in other declarations, at least not automatically".

Is my approach right at the beginning, and more importantly is there a simpler, plainer way to explain it?


It has nothing to do with anything being optional.

But instead of defining a function which takes two parameters, you can define one which takes only one parameter, and returns a function which takes the other parameter.

The end result is the same (the caller ends up providing two parameters), but with currying, you only provide one at a time.

0

精彩评论

暂无评论...
验证码 换一张
取 消