Is it possible to unify the concepts of inheritance and parametric polymorphism?

I wonder if it is possible to unify the concepts of inheritance and parametric polymorphism ("generics") in general, especially in relation to variance, but also in terms of how ("syntax") and where (site-site / declaration-site) should they be defined?

Consider this point of view:

  • Imprint e. g S <: Tcan be perceived as a joint behavior, since input arguments that accept Talso accept S.
  • Changing the “variance of the inheritance model” to an invariant one is possible only on the definition side, prohibiting subtyping (for example, adding a modifier finalto a class definition), contrasting is not possible, as I saw in most cases
  • Parametric polymorphism is invariant by default, but can be done with a co-combination

There seems to be a non-price concept mismatch between them, given

  • pain languages ​​are generated allowing "unsafe" covariance (for example, String[] <: Object[]in Java / C #)
  • differences in how inheritance / parametric polymorphism is declared and used compared to inheritance

In some languages, it can be seen that both work together well, although, for example,

class Foo extends Ordered[Foo]

to implement ordering / comparison behavior.

  • , (, , )? , ?
  • , ?
  • / , ?
  • - , /- ?
+5
1

/ . , X, Y, Z . , a → b a b. <: , , "". ⇒ " ". :

X <: Y ⇒ (Z → X) <: (Z → Y)
X <: Y ⇒ (Y → Z) <: (X → Z)

( ) ( ). , - , , . , ( ).

, . (), (), (). , , .

, Scala . , Scala, , , . , , . ?

, , - " " .

+4

All Articles