我尝试关注https://typelevel.org/cats/typeclasses/applicative.html
trait Applicative[F[_]] extends Functor[F] {
def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]
def pure[A](a: A): F[A]
}
// Example implementation for right-biased Either
implicit def applicativeForEither[L]: Applicative[Either[L, *]] = new Applicative[Either[L, *]] {
def product[A, B](fa: Either[L, A], fb: Either[L, B]): Either[L, (A, B)] = (fa, fb) match {
case (Right(a), Right(b)) => Right((a, b))
case (Left(l) , _ ) => Left(l)
case (_ , Left(l) ) => Left(l)
}
def pure[A](a: A): Either[L, A] = Right(a)
def map[A, B](fa: Either[L, A])(f: A => B): Either[L, B] = fa match {
case Right(a) => Right(f(a))
case Left(l) => Left(l)
}
}
它无法编译并出现错误:
未找到:类型 * 隐式 def applicativeForEither[L]: Applicative[Either[L, *]] = new Applicative[Either[L, *]] {
在 cat 中,它使用 '?' 而不是'*'(例如EitherTFunctor),但当我复制粘贴它时它也无法编译。
我应该怎么做才能修复它?