【发布时间】:2012-11-20 16:50:23
【问题描述】:
谁能告诉我这个函数定义有什么问题?
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)
^
这里有什么问题?
【问题讨论】:
标签: scala type-mismatch