[英]Scala Currying Functions vs. Basic Functions Explained
What is the difference between the following two functions definition? 以下两个函数定义有什么区别? Please bear with me if this has been answered before.
如果以前已经回答过,请耐心等待。 I don't know what is the first type of function called to search for properly.
我不知道第一种被称为正确搜索的函数是什么。
def f1(a: String, b: T)(c: String, d: String, e: String = "_id"): Unit = ???
and 和
def f1(a: String, b: T, c: String, d: String, e: String = "_id"): Unit = ???
I know that it is similar to the question mentioned here . 我知道它类似于这里提到的问题。
A1 : A1 :
A2 : A2 :
EDIT Advantages / Disadvantages concept-wise 编辑优势/劣势概念方面
lambda calculus
semplicity: lambda calculus
semplicity:
In theoretical computer science, currying provides a way to study functions with multiple arguments in very simple theoretical models such as the lambda calculus in which functions only take a single argument.
在理论计算机科学中,currying提供了一种在非常简单的理论模型中研究具有多个参数的函数的方法,例如lambda演算,其中函数仅采用单个参数。
(nice example here: https://en.wikipedia.org/wiki/Currying#Motivation ) (这里很好的例子: https : //en.wikipedia.org/wiki/Currying#Motivation )
Curried functions needs closure
support: Curried函数需要
closure
支持:
Curried functions may be used in any language that supports closures
Curried函数可以用于支持闭包的任何语言
Uncurried functions for performance : 未履行的绩效功能:
Uncurried functions are generally preferred for efficiency reasons, since the overhead of partial application and closure creation can then be avoided for most function calls.
出于效率原因,通常优选未计算的函数,因为对于大多数函数调用,可以避免部分应用和闭包创建的开销。
Curry–Howard correspondence: 库里 - 霍华德的通信:
The existence of currying and uncurrying is equivalent to the logical theorem
currying和uncurrying的存在等同于逻辑定理
as tuples (product type) corresponds to conjunction in logic, and function type corresponds to implication.
因为元组(产品类型)对应于逻辑中的连接,而函数类型对应于含义。
Source: https://en.wikipedia.org/wiki/Currying 资料来源: https : //en.wikipedia.org/wiki/Currying
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.