-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
So I enthusiastically started using Eval
, but then noticed that Eval[A]
is not covariant in A
and this creates problems for me.
Now I understand that variance is a hard and I understand why type-classes are invariant and so on, but Eval
is supposed to be a replacement for by-name and for Function0[+R]
parameters and the problem is that functions in Scala are covariant in their return, along with most immutable data-structures from the standard library. And so when you want covariance, then Eval
ends up not being a replacement for by-name parameters.
My use-case is the ability to use F[Nothing]
for empty containers when it comes to things like this:
trait Sequence[+A] {
def continueWith[B >: A](other: => Sequence[B]): Sequence[B]
}
In the above, the ability to pass in a Sequence[Nothing]
sure comes in handy. And replacing that parameter with an Eval
doesn't work as well as it does with a by-name parameter.
Link to the Gitter conversation: https://gitter.im/typelevel/cats?at=56e95650c7364f7926bf7d38