I am trying to implement a cats Monad
instance for a type that has multiple type parameters. I looked at the cats Either
instance to see how it was done there. Part of the Either
Monad
instance code from cats is copied below:
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)
}
}
It fails to compile with the error: error: not found: type ?
What is the ?
type and how can I use it when creating instances for my own types?