为什么 curried 构造函数会在部分函数应用程序中抛出错误?
Why does a curried constructor throw an error on partial function application?
当我尝试创建柯里化构造函数时,例如
class MyClass(a: Int, b: Int)(c: String) {
// Some Implementation
}
为什么部分应用像
val partialConstructor = new MyClass(x, y)
导致错误消息
missing argument list for constructor MyClass in class MyClass
您将柯里化函数与多参数列表函数混淆了。看看 this answer 为什么有多个参数列表的函数。
对于你的例子,你应该明确地说你想要一个柯里化函数
val partialConstructor = new MyClass(x, y)(_)
当我尝试创建柯里化构造函数时,例如
class MyClass(a: Int, b: Int)(c: String) {
// Some Implementation
}
为什么部分应用像
val partialConstructor = new MyClass(x, y)
导致错误消息
missing argument list for constructor MyClass in class MyClass
您将柯里化函数与多参数列表函数混淆了。看看 this answer 为什么有多个参数列表的函数。
对于你的例子,你应该明确地说你想要一个柯里化函数
val partialConstructor = new MyClass(x, y)(_)