, , , .:) , ML, Scala, Scala . Scala , , (, ML, Rust ..) . , Scala / ( ML ).
ML ( Scala) ( Scala), Scala ( ). , / Scala, .
, Scala, , , , ( , ML), :
trait A {
type X
def getX: X
def setX(x: X): Unit
}
def foo(a: A) = a.setX(a.getX)
foo
Scala a.X
, , , . Rust, .
Scala, Dotty, , , . , , Scala .
: , , , / Scala, :
def bar(a: A, b: A) = a.setX(b.getX)
:
error: type mismatch;
found : b.T
required: a.T
def foo(a: A, b: A) = a.setX(b.getX)
^
, a.T
b.T
. , , :
def bar(a: A)(b: A { type X = a.X }) = a.setX(b.getX)
:
def bar[T](a: A { type X = T }, b: A { type X = T }) = a.setX(b.getX)
, , ( A[_]
A[T] forSome { type T }
, A , ).