我有以下示例仿函数:
Button1_Click ThreadID - 9
0
1
2
...
9998
9999
10000
BackgroundWorker1_RunWorkerCompleted - State: True
编译器在最后一行抱怨:
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
object Functor {
implicit val listFunctor: Functor[List] = new Functor[List] {
def map[A, B](fa: List[A])(f: (A) => B): List[B] = fa.map(f)
}
}
Functor.listFunctor.map(List(1,2,3,4))(_ + _)
我做错了什么?
答案 0 :(得分:2)
_ + _
是一个函数,它接受两个参数并返回它们的总和,这不是map
所期望的。请尝试以下方法:
Functor.listFunctor.map(List(1,2,3,4))(i => i + i)