0

After I solidified my understanding of why a parameter in a method is a contravariant position with SO post scala contravariant position on method

I am looking at List[+A] in scala and I see this method which is fine since the parameter position is contravariant

def contains[A1 >: A](elem: A1)

What I don't get is the :: method definition which seems like that would not compile

def ::(x: A): List[A]

What is going on with this method? oh, they hide the real signature?

def ::[B >: A](x: B): List[B]

ok, then why do they hide the real signature?

Community
  • 1
  • 1
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
  • different styles of scaladoc, probably by different authors – soulcheck Sep 30 '14 at 23:09
  • 1
    duplicate of http://stackoverflow.com/questions/26089746/how-to-explain-map-map-result see the comments about "scaladoc, use cases and damn lies". – som-snytt Oct 01 '14 at 00:03

1 Answers1

2

Scaladoc entries marked [use case] are presenting the most common cases in terms of type parameters first, often leading to a simpler construction for beginners. If you expand that, you get the full signature.

For a type Foo[+A], you can implement methods that take A-like arguments by introducing a type parameter B >: A, because now you cannot provide a value that is a sub-type of A which would violate the type-soundness. In most cases you will prepend to a List[A] other elements of type A, therefore the doc simplification.

0__
  • 66,707
  • 21
  • 171
  • 266