【问题标题】:Why does a curried constructor throw an error on partial function application?为什么柯里化构造函数在偏函数应用程序上会抛出错误?
【发布时间】:2017-06-06 06:58:23
【问题描述】:

当我尝试创建一个柯里化构造函数时,比如

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

【问题讨论】:

    标签: scala constructor currying


    【解决方案1】:

    您将柯里化函数与多个参数列表的函数混淆了。看看this answer为什么会有多个参数列表的函数。

    对于你的例子,你应该明确地说你想要一个柯里化函数

    val partialConstructor = new MyClass(x, y)(_)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-16
      • 2019-03-26
      • 2016-07-29
      • 2016-01-01
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      相关资源
      最近更新 更多