This is a special syntax for the so-called lambdas type, which was added by the plug-in of a good projector .
Either[A, ?]
is a shortcut for
({type L[X] = Either[A, X]})
All code descriptors for
import cats.Monad object EitherMonad { implicit def instance[A]: Monad[({type L[X] = Either[A, X]})#L] = new Monad[({type L[X] = Either[A, X]})#L] { 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) } }
The lambda type looks scary, but they are essentially a very simple concept. You have a thing that takes two type parameters, like Either[A, B] . You want to provide a monad instance for Either, but trait Monad[F[_]] accepts only one type parameter. But in principle, this is normal, since your monad instance concerns only the argument of the second ("right") type. A lambda type is just a way to “fix” an argument of the first type so that you have the correct form.
If you did the same thing at the level of value, you would not even think about it twice. You got a function of two arguments
val f: (Int, Int) => Int = ...
And something that you want to pass f that takes only one argument
def foo(x: Int => Int) = ...
The only way to make things fit is to fix one of the arguments
foo(x => f(1, x))
And this is exactly what lambda type does at the level level.
source share