柯里化只是“可选参数”?
我在网上读到一个人的声明,说“柯里化只是一种具有可选参数的奇特方式”。凭直觉,我觉得这个说法很肤浅而且错误,但我不能真正指出它,可能是因为我对 lambda 演算没有足够的知识。
当我尝试解释差异时,我的解释跨越了多个段落,主要归结为“柯里化是将函数声明的所有变体与较少数量的参数作为类型。但是你不能将带有可选参数的函数的所有组合作为有效类型,并且在其他声明中使用它们,至少不会自动使用”。
我的方法一开始就正确吗?更重要的是,有没有更简单、更简单的方法来解释它?
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 coming 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它与可选的任何内容无关。
但是,您可以定义一个只接受一个参数的函数,并返回一个接受另一个参数的函数,而不是定义一个接受两个参数的函数。
最终结果是相同的(调用者最终提供两个参数),但通过柯里化,您一次只提供一个。
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.