5
我正在尝试为具有多个类型参数的类型实现一个cat Monad
实例。我看着猫的实例,看看它是如何完成的。从猫Either
Monad
实例代码的一部分复制如下:什么是?类型?
import cats.Monad
object EitherMonad {
implicit def instance[A]: Monad[Either[A, ?]] =
new Monad[Either[A, ?]] {
def pure[B](b: B): Either[A, B] = Right(b)
def flatMap[B, C](fa: Either[A, B])(f: B => Either[A, C]): Either[A, C] =
fa.right.flatMap(f)
}
}
它失败,错误编译:error: not found: type ?
什么是?
型,我怎么能创造我自己的情况下,当使用类型?
'?'是一个有效的符号,在这种情况下它就像'A'。 –