Hacker News new | ask | show | jobs
by hinkley 2926 days ago
I’m a little surprised you only got two answers, because I’m pretty sure the answer depends on how you look at the problem. Mine is this:

A function has variance because the types of its inputs or outputs are in a hierarchy.

An object type system (or I suppose even a functor system?) with generics might leverage variance to make sure that the behavior of its own methods is consistent with the Substitution Principle (LSP).

And many people will tldr this into variance being the tool to give you a type system that is LSP compatible. But it’s all about the operations, consuming and emitting types.

1 comments

I think like this too. Would only like to add that I believe a type parameter is *variant in relation to a function/method, not just by itself. That's why some people say "appears in a covariant position " and so on.