I'm studying Scalaz 7, the type class system is so abstract, and one thing I can not understand is that why Bind.ap
is implemented by bind
in such a way.
trait Apply[F[_]] extends Functor[F] { self =>
def ap[A,B](fa: => F[A])(f: => F[A => B]): F[B]
....
}
trait Bind[F[_]] extends Apply[F] { self =>
/** Equivalent to `join(map(fa)(f))`. */
def bind[A, B](fa: F[A])(f: A => F[B]): F[B]
override def ap[A, B](fa: => F[A])(f: => F[A => B]): F[B] = bind(f)(f => map(fa)(f))
....
}
I know we can treat F[A => B]
as F[C]
, so first argument of bind
make sense, but the second argument requires a A => F[B]
, how is f => map(fa)(f)
equivalent to A => F[B]
??