title: Avoiding type casting in pattern matching
body: <p>Given a hypothetical mutable linked list (let's assume this is a given structure -- so no suggestions about changing it, please):</p>
  
  <pre><code>trait CList[T]
  trait CNil [T] extends CList[T]
  trait CCons[T] extends CList[T] {
    def head: T
    def tail: CList[T]
  }
  </code></pre>
  
  <p>And given Scala's type erasure, how can I iterate through it without casting:</p>
  
  <pre><code>@annotation.tailrec def lastValue[T](l: CList[T]): Option[T] = l match {
    case _: CNil [_] =&gt; None
    case c: CCons[_] =&gt; lastValue(c.asInstanceOf[CCons[T]]) // ouch!
  }
  </code></pre>
  
  <p><code>CList</code> is invariant in <code>T</code> so there should be way to accomplish this?</p>