【发布时间】:2013-11-29 11:05:57
【问题描述】:
为什么类型推断器放弃了这个:
def test(a: Seq[Int], b: Seq[Int]) = (a, b).zipped.map((_ + _) / 2) // no
像这样:
<console>:35: error: missing parameter type for expanded function
((x$1, x$2) => x$1.$plus(x$2))
def test(a: Seq[Int], b: Seq[Int]) = (a, b).zipped.map((_ + _) / 2)
^
这是一个奇怪的微妙之处,似乎与括号有关。例如,不使用中缀语法也可以:
def test(a: Seq[Int], b: Seq[Int]) = (a, b).zipped.map(_.+(_) / 2) // yes
如果我为了好玩而添加另一对括号,它会再次失败:
def test(a: Seq[Int], b: Seq[Int]) = (a, b).zipped.map((_.+(_)) / 2) // no
【问题讨论】:
标签: scala type-inference