How to understand "The dispersion position of a parameter of a method is opposite to the dispersion position of a proposal to include a parameter."

I see this suggestion scala specification (pdf) :

The dispersion position of the parameter of the method is opposite to the dispersion position of the proposal to include the parameter.

This is on page 44.

But I can’t understand it. Could you give me some samples?

+4
source share
1 answer

So, let's start with a motivational example. Suppose I write the following:

class Foo[+A] {
  def foo(a : A) = ???
}

, A +, , Foo A, X <: Y, Foo[X] <: Foo[Y]. , , Foo[X], , Foo[Y]:

def bar(a : Y, x : Foo[Y]) = {
  x.foo(a)
}

bar x.foo Y. x Foo[X], x Y - Object , String - , Object , . , Foo - A , - .

, Scala, , - , Scala , , , 't - Foo . , , , , - , (, ) .

, . , :

class Foo[A, B] {
  def foo(a : A) = {
    def bar(b : B) = ???
  }
}

Foo , , , bar . :

class Foo[-A, +B] {
  def foo(a : A) = {
    def bar(b : B) = ???
  }
}
+7

Source: https://habr.com/ru/post/1538666/


All Articles