title: How to handle simple polymorphism with case classes?
body: <p>I have the following case classes:</p>
  
  <pre><code>object Fields {
    abstract class Base{
      def getString: String
    }
    case class A() extends Base{
      def getString = "A+++"
    }
    case class B() extends Base{
      def getString = "B++"
    }
  
    def fieldsToString(fields: List[Base]): String = {
      fields.tail.foldLeft(s"${fields.head.getString}") {(acc, f) =&gt;
        acc + s",${f.getString}"
      }
    }
  }
  </code></pre>
  
  <p>Then I tried to call this function in the following way:</p>
  
  <pre><code> val fields = List(A, B, A)
   val result = Fields.fieldsToString(fields)
  </code></pre>
  
  <p>which gives me the following error: </p>
  
  <pre><code>type mismatch;
  [error]  found   : List[scala.runtime.AbstractFunction0[Product with Serializable 
  with Fields.Base] with Serializable]
  </code></pre>
  
  <p>So I thought I needed to introduce covariance:</p>
  
  <pre><code> def fieldsToString[T &gt;: Base](fields: List[T]): String = {
          fields.tail.foldLeft(s"${fields.head.getString}") {(acc, f) =&gt;
            acc + s",${f.getString}"
          }
        }
  </code></pre>
  
  <p>Which then gives me the following compile error:</p>
  
  <pre><code>do not conform to method fieldsToString's type parameter bounds [T &lt;: Fields.Base]
  </code></pre>
  
  <p>What exactly is the problem, is this due to the case classes, do they behave differently then normal classes?</p>