title: Scala flatten List
body: <p>I want to write a function that flats a List.</p>
  
  <pre><code>object Flat {
    def flatten[T](list: List[T]): List[T] = list match {
      case Nil =&gt; Nil
      case head :: Nil =&gt; List(head)
      case head :: tail =&gt; (head match {
        case l: List[T] =&gt; flatten(l)
        case i =&gt; List(i)
      }) ::: flatten(tail)
    }
  }
  
  object Main {
    def main(args: Array[String]) = {
      println(Flat.flatten(List(List(1, 1), 2, List(3, List(5, 8)))))
    }
  }
  </code></pre>
  
  <p>I don't know why it don't work, it returns <code>List(1, 1, 2, List(3, List(5, 8)))</code> but it should be <code>List(1, 1, 2, 3, 5, 8)</code>.</p>
  
  <p>Can you give me a hint?</p>