为什么不能解决这种类型

时间:2017-05-04 09:53:56

标签: scala

我有以下示例仿函数:

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))(_ + _)

我做错了什么?

1 个答案:

答案 0 :(得分:2)

_ + _是一个函数,它接受两个参数并返回它们的总和,这不是map所期望的。请尝试以下方法:

Functor.listFunctor.map(List(1,2,3,4))(i => i + i)
相关问题