title: Flatten a list of lists
body: <p>I have to write a function that flattens a list of lists.</p>
  
  <p>For example <code>flatten [] = []</code> or <code>flatten [1,2,3,4] = [1,2,3,4]</code> or <code>flatten [[1,2],[3],4,5]] = [1,2,3,4,5]</code></p>
  
  <p>I'm having trouble with the being able to match the type depending on what is given to the flatten function.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>data A a = B a | C [a] deriving (Show, Eq, Ord)
  
  flatten::(Show a, Eq a, Ord a)=&gt;A a -&gt; A a
  flatten (C []) = (C [])
  flatten (C (x:xs) ) = (C flatten x) ++ (C flatten xs)
  flatten (B a) = (C [a])
  </code></pre>
  
  <p>From what I can tell the issue is that the <code>++</code> operator is expecting a list for both of its arguments and I'm trying to give it something of type <code>A</code>.  I've added the <code>A</code> type so the function can either get a single element or a list of elements.</p>
  
  <p>Does anyone know a different way to do this differently, or explain what I can do to fix the type error? </p>