3 ms·
A generic type with a covariant parameter can be seen as a covariant functor if you pick the right category. Specifically you need the category where the objec
by contravariant 11y ago
A generic type with a covariant parameter can be seen as a covariant functor if you pick the right category.
Specifically you need the category where the objects are types and the morphisms indicate inheritance (i.e. A -> B means that A is a subtype of B).
Then a functor F is covariant if A -> B implies F(A) -> F(B). Which is precisely what it means to be a covariant generic type.
Note: you shouldn't confuse this category with the category where the objects are types and the morphisms are functions that map values of one type to values of another type.