Syntax for partial application of curry functions with inverse associative infix notation

In other words, is there a good reason why this should not be compiled?

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

Here are some workarounds:

def f(xs: List[Int]) = xs./:(0) _
def f(xs: List[Int]): ((Int, Int) => Int) => Int = (0 /: xs)

but my question is mostly about the correct syntax in general.

+5
source share
2 answers

I fixed it just now, but I can’t check it yet, because it requires a specification change.

scala> def f(xs: List[Int]) = (0 /: xs) _
f: (xs: List[Int])(Int, Int) => Int => Int

scala> f(1 to 10 toList)
res0: (Int, Int) => Int => Int = <function1>

scala> res0(_ + _)
res1: Int = 55

, spec "e1 op e2", op - {val x = e1; e2.op(x)} , , e2.op(e1) , https://issues.scala-lang.org/browse/SI-1980. .

+2

. scala , :

def f(xs: List[Int]) = (0 /: xs) _

2.9.1.final 2.8.2.final, 2.7.7.final (Iterable vs. TraversableOnes), , - .

def f(xs: List[Int]) = (0 /: xs) _
<console>:4: error: missing arguments for method /: in trait Iterable;
follow this method with `_' if you want to treat it as a partially applied function

, , - scala.

def f(xs: List[Int]): (Int, Int) => Int => Int = (0 /: xs)

scala 2.9.1.final:

 found   : (Int, Int) => Int => Int
 required: (Int, Int) => Int => Int

, .

scala 2.8.2.final:

 found   : => ((Int, Int) => Int) => Int
 required: (Int, Int) => (Int) => Int

Weird => , 2.7.7. .

scala 2.7.7.final:

 found   : ((Int, Int) => Int) => Int
 required: (Int, Int) => (Int) => Int

found, -, , - .

scala bugtracker , . , ( ? , ).

+2

All Articles