title: How to define case classes with members with unbound type parameters?
body: <p>Given a class definition with bound type parameter <code>Animal[A &lt;: String]</code> it seems that the Scala compiler does not infer <code>B &lt;: String</code> from <code>Animal[B]</code>. Is the inference allowed? How to help the compiler to do the inference?</p>
  
  <p>Below is a concrete example with case classes where the lack of this inference is a problem.</p>
  
  <p>Consider the following case class hierarchy:</p>
  
  <pre><code>sealed trait Person[+T &lt;: Person[T]]
  case class Student() extends Person[Student]
  case class Professor() extends Person[Professor]
  </code></pre>
  
  <p>I need to define a case class <code>University</code> which I can instantiate with a variable of type <code>Person[_]</code>, for example <code>val p: Person[_] = Student()</code>. I thought this would work with the following definition:</p>
  
  <pre><code>case class University(p: Person[_])
  </code></pre>
  
  <p>But this fails compiling with the error:</p>
  
  <pre><code>type arguments [Any] do not conform to trait Person's type parameter bounds [+T &lt;: Person[T]]
  </code></pre>
  
  <p>If I bind the type parameter of the case class <code>University</code> it compiles (it also compiles with unbounded parameters if i drop the <code>case</code> keyword but this is not an option in my case):</p>
  
  <pre><code>case class BoundUniversity[P &lt;: Person[P]](p: Person[P])
  </code></pre>
  
  <p>But this parametrized version cannot be instantiated with an unbounded variable of type <code>Person[_]</code>:</p>
  
  <pre><code>val p: Person[_] = Student()
  BoundUniversity(p)
  </code></pre>
  
  <p>fails compiling with:</p>
  
  <pre><code>inferred type arguments [_$1] do not conform to method apply's type parameter bounds [P &lt;: Person[P]]
  </code></pre>
  
  <p>The same error happens for a method with a bound argument like:</p>
  
  <pre><code>def general[P &lt;: Person[P]](p: P) = println(p)
  </code></pre>
  
  <p>so this is not specific to class constructors.</p>
  
  <p>Two questions:</p>
  
  <ol>
  <li><p>The type <code>Person</code> is defined with parameter bounds <code>Person[+T &lt;: Person[T]]</code>, so that each instance of this type is insured to respect those bounds: <code>val p: Person[P]</code> implies that <code>P &lt;: Person[P]</code>; or am I missing something? So how can I make this clear to the compiler so that it doesn't complain?</p></li>
  <li><p>How/Can I define a case class with members with unbound type parameter like <code>case class University(p: Person[_])</code>?</p></li>
  </ol>