有人可以告诉我这个函数定义有什么问题吗?
def incr[Int](l: List[Int]): List[Int] =
l.foldRight(List[Int]())((x,z) => (x+1) :: z)
Scala 编译器抱怨传递给的函数体中的类型不匹配foldRight
:
<console>:8: error: type mismatch;
found : Int(1)
required: String
l.foldRight(List[Int]())((x,z) => (x+1) :: z)
^
这里有什么问题?