title: Use case and examples for type pattern with type variable
body: <p>I found out reading the spec that scala supports binding type variables when doing a type pattern match:</p>
  
  <pre><code>Map(1 -&gt; "one", 2 -&gt; "two") match {
    case l: Map[k, v] =&gt;
      // binds k to Int and v to String
      // k and v are types as shown here:
      val i: Iterator[Tuple2[k, v]] = l.iterator
      println(i.mkString(", "))
  }
  </code></pre>
  
  <p>Are there any fancy things or practical things I can do with this? Or binding type variables is only useful for type documentation purpose?</p>
  
  <p>It occurred to me that Scala sometimes needs type annotations, such as defining function, so I tried:</p>
  
  <pre><code>def prepender(obj: Any) = obj match {
    case xs: List[a] =&gt; (x: a) =&gt; x :: xs
    case opt: Some[a] =&gt; (x: a) =&gt; x :: Nil
  }
  </code></pre>
  
  <p>But then the type of the return function is weird:</p>
  
  <pre><code>prepender: (obj: Any)a with a =&gt; List[Any] forSome { type a; type a }
  
  scala&gt; val p = prepender(List(1,2))
  p: a with a =&gt; List[Any] forSome { type a; type a } = &lt;function1&gt;
  
  scala&gt; p(1)
  &lt;console&gt;:10: error: type mismatch;
   found   : Int(1)
   required: a(in value res7) with (some other)a(in value res7) where 
     type (some other)a(in value res7), type a(in value res7)
  </code></pre>