On October 23, 2016 11:09:16 PM EDT, ace_coder <
ama...@gmail.com> wrote:
>How do I constrain a covariant type to invariant type so that I can
>pass it
>as a type parameter to EitherT?
>
>Something of the form:
>
>type Method[+T] = EitherT[F, Int, T] // Error: Usage of
>covariant
>type in invariant position.
Method can only be defined as Method[T] here. Technically, EitherT[F, Int, _ <: T] has the semantics you want and T in covariant position (one implication of the covariance of any Cv[+A] is that for all T, Cv[T] = Cv[_ <: T]), but scalac isn't great at inferring its usage, never mind implicit conversions from it.
Covariant type constructors widen to invariant, but not vice versa, and the invariance of EitherT is deliberate; see
https://failex.blogspot.com/2016/09/the-missing-diamond-of-scala-variance.html for explanation.
--
Stephen Compall
If anyone in the MSA is online, you should watch this flythrough.