title: Apparent loss of type information when mapping over a list
body: <p>I'm trying to declare a case class that takes two type parameters: a concrete type <code>A</code> and a type constructor <code>D</code>, constrained to be a subclass of a known one. My case class would then contain a <code>List[D[A]]</code>.</p>
  
  <p>The problem I'm encountering is that, whenever I map on that list, I seem to lose the information of the type contained by <code>D</code>.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>// Represents a named collection of documents of type A
  trait Documents[A] {
    def name: String
    def take(target: Int): Documents[A]
  
    // [...]
  }
  
  // Represents a collection of named collections of documents.
  // A is the type of a document, D that of a named collection of documents
  case class Data[A, D[_] &lt;: Documents[_]](docs: List[D[A]]) {
    // Makes sure no D contains more than target documents
    def cap(target: Int): Data[A, Documents] = {
      Data(docs.map(_.take(target)))
    }
  
    // [...]
  }
  </code></pre>
  
  <p>This fails to compile with the following confusing (to me) error message:</p>
  
  <pre><code>type mismatch;
  [error]  found   : List[Documents[_]]
  [error]  required: List[Documents[A]]
  [error]     Data(docs.map(_.take(target)))
  [error]                  ^
  </code></pre>
  
  <p>I don't understand how applying a function <code>D[A] =&gt; Documents[A]</code> to a <code>D[A]</code> can yield a <code>Documents[_]</code>...</p>