Why is Task not co-variant?

According to someone who may be in the know… The justification is that the advantage of covariance is outweighed by the disadvantage of clutter (i.e. everyone would have to make a decision about whether to use Task or ITask in every single place in their code). It sounds to me like there is not a … Read more

Does C# support return type covariance?

UPDATE: This answer was written in 2011. After two decades of people proposing return type covariance for C# they have been implemented. See Covariant Returns in https://devblogs.microsoft.com/dotnet/c-9-0-on-the-record/. It sounds like what you want is return type covariance. C# does not support return type covariance. Return type covariance is where you override a base class method … Read more

Why is Scala’s immutable Set not covariant in its type?

Set is invariant in its type parameter because of the concept behind sets as functions. The following signatures should clarify things slightly: trait Set[A] extends (A=>Boolean) { def apply(e: A): Boolean } If Set were covariant in A, the apply method would be unable to take a parameter of type A due to the contravariance … Read more