【发布时间】:2011-10-12 05:39:15
【问题描述】:
换句话说,这有什么不应该编译的充分理由吗?
def f(xs: List[Int]) = xs.foldLeft(0) _ // OK
def f(xs: List[Int]) = (xs :\ 0) _ // OK
def f(xs: List[Int]) = (0 /: xs) _
<console>:15: error: missing arguments for method /: in trait TraversableOnce;
follow this method with `_' if you want to treat it as a partially applied function
以下是一些解决方法:
def f(xs: List[Int]) = xs./:(0) _
def f(xs: List[Int]): ((Int, Int) => Int) => Int = (0 /: xs)
但我的问题主要是关于一般的正确语法。
【问题讨论】:
-
+1,当在表达式
def f(xs: List[Int]): (Int, Int) => Int => Int = (xs :\ 0)found : (Int, Int) => Int => Intrequired: (Int, Int) => Int => Int中省略一对括号时,我发现了另一个令人困惑的编译器错误
标签: scala currying infix-notation partial-application associativity