title: Why String type-checks with A, but List[Int] does not with List[A]?
body: <p>I’m reading through the section on local type inference in Scala’s spec (§6.26.4), more specifically the example 6.26.3. </p>
  
  <p>For the example, there are the following functions and a value defined:</p>
  
  <pre><code>def cons[A](x: A, xs: List[A]): List[A] = x :: xs
  def nil[B]: List[B] = Nil
  val xs = cons(1, nil)
  </code></pre>
  
  <p>where <code>xs</code> is inferred to be of type <code>List[Int]</code>. So far so good. </p>
  
  <p>Then, the example works with the following value:</p>
  
  <pre><code>val ys = cons("abc", xs)
  </code></pre>
  
  <p>That is in turn inferred to be of type <code>List[Any]</code>, which perfectly makes sense. What does not make much sense to me is the reasoning for it. It says that the second argument is typed with the expected type <code>List[a]</code> (why suddenly lowercase letter btw.?), which is said to fail, because <code>List[Int]</code> (the type of <code>xs</code>) is not a subtype of <code>List[a]</code>. So they retry with typing it as <code>List[undefined]</code>, which succeeds. But, the first argument is typed as <code>String</code>, no questions asked, although its expected type is <code>a</code> (or <code>A</code>?). </p>
  
  <p>Moreover, the second strategy only works by replacing type parameters with <code>undefined</code> in the type, not the type itself with <code>undefined</code> (or is that implied somehow?). </p>
  
  <p>Now the question, <code>a</code> being a type constant, why <code>String</code> is (apparently) a subtype of <code>a</code>, while <code>List[Int]</code> is not a subtype of <code>List[a]</code>, even though <code>List</code> is covariant? </p>