在我的代码中,我有以下内容:
type Occurrences = List[(Char, Int)]
def subtract(x: Occurrences, y: Occurrences): Occurrences = {
val yMap = y.toMap
x foldLeft (List[(Char, Int)]()) { // ERROR
case (a: List[(Char, Int)], xe: (Char, Int)) =>
if(yMap.contains(xe._1)) (xe._1 -> (xe._2 - yMap(xe._1))) :: a
else a
}
}
它在编译时失败,就在代码中错误标记之前的
{
处。错误信息如下:
1) 这怎么可能呢?据我所见,这里没有类型信息的曲解空间,而且我在互联网上发现了很多这样的例子。我该怎么修复它?missing parameter type for expanded function The argument types of an anonymous function must be fully known. (SLS 8.5) Expected type was: Int
2) 它为什么最终认为期望的类型是
Int
?