//a curry function
def find(a: Seq[Int])(sort: (Int, Int) => Boolean)
//My attempt
val findWithBiggerSort = find(_)((a,b) => a > b)
findWithBiggerSort
无法正常工作,发生编译错误:
scala> def find(a: Seq[Int])(sort: (Int, Int) => Boolean)
| ={}
find: (a: Seq[Int])(sort: (Int, Int) => Boolean)Unit
scala> val findWithBiggerSort = find(_)((a,b) => a > b)
<console>:11: error: missing parameter type for expanded function ((x$1) => find(x$1)(((a, b) => a.$greater(b))))
val findWithBiggerSort = find(_)((a,b) => a > b)
^
如何绑定第二个咖喱参数?
如何将第二个参数绑定为此
def find(a: Seq[Int], b: String)(sort: (Int, Int) => Boolean)
答案 0 :(得分:2)
您有两个问题:
sort
功能的类型错误 - 您需要(Int, Int) => Boolean
,但提供(Int, Int) => Int
。如果您将其更改为:
val findWithBiggerSort = find(_)((a,b) => (a > b))
您在_
中提供的find (_)
参数缺失类型时收到错误消息。如果你提供这种类型,它就会编译,即
val findWithBiggerSort = find(_:Seq[Int])((a,b) => (a > b))
或
val findWithBiggerSort = find(_:Seq[Int])(_ > _)