title: Scala pattern matching in the for construct
body: <p>I have the following data model which I'm going to do pattern matching against later:</p>
  
  <pre><code>abstract class A
  case class C(s:String) extends A
  
  abstract class B extends A
  case class D(i:Int) extends B
  case class E(s:Int, e:Int) extends B
  </code></pre>
  
  <p>A is the abstract super type of the hierarchy. C is a concrete subclass of A. Other concrete subclasses of A are subclasses of B which is in turn a subclass of A.</p>
  
  <p>Now if I write something like this, it works:</p>
  
  <pre><code>def match(a:A) a match {
     a:C =&gt; println("C")
     a:B =&gt; println("B")
  }
  </code></pre>
  
  <p>However, in a for loop I cannot match against B. I assume that I need a constructor pattern, but since B is abstract, there is no constructor pattern for B.</p>
  
  <pre><code>val list:List[A] = List(C("a"), D(1), E(2,5), ...)
  
  for (b:B &lt;- list) println(b)  // Compile error
  for (b@B &lt;- list) println(b)  // Compile error
  </code></pre>
  
  <p>Here, I would like to print only B instances. Any workaround for this case? </p>