Cats: Variance

Created on 3 Jul 2018  路  3Comments  路  Source: typelevel/cats

Do you know why Validated is covariant on its two type (like Either) but EitherT is invariant?

sealed abstract class Validated[+E, +A]
final case class EitherT[F[_], A, B]

Most helpful comment

Wouldn鈥檛 it require F[+_]? Which limits us. Note Functor has widen and Bifunctor has leftWiden which you can use like explicit covariance.

All 3 comments

Wouldn鈥檛 it require F[+_]? Which limits us. Note Functor has widen and Bifunctor has leftWiden which you can use like explicit covariance.

@johnynek you're probably right, make sense. I guess it is just annoying that we have to treat Either and EitherT differently in a for comprehension. It doesn't help that intellij doesn't recognize leftWiden (but that's another issue).

Has anyone got any clue why IntelliJ doesn't recognise leftWiden?

Was this page helpful?
0 / 5 - 0 ratings