Hacker News new | past | comments | ask | show | jobs | submit login

You are right, I probably did not express my idea clearly. What I meant is that there is only one meaningful pattern: returns are covariant and arguments are contravariant. If it is so (and the articles seems to confirm this) then why do we need special annotations? The system could itself assume that any argument (by default) is contravariant and any return (by default) is covariant. Does it make sense?



> The system could itself assume that any argument (by default) is contravariant and any return (by default) is covariant.

I guess languages could infer variance for generic parameters on methods/functions, and perhaps should - it would align with how type systems generally work. But that's a small part of the use case - variance mainly matters when you have generic values. If we have a Frobnicator[A, B] it would be very difficult for the language to infer whether variance for frobnicator values should run like for A => B, like for B => A, or some other way.


Except that in many languages you have also input/ouput parameters that should be invariant, I agree.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: