Skip to content

Make Eval covariant in its type parameter #934

@alexandru

Description

@alexandru

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions