title: No instance for (Show a0) arising from a use of `print' The type variable `a0' is ambiguous
body: <pre><code>data NestedList a = Elem a | List [NestedList a]
  flatten :: NestedList a -&gt; [a]
  flatten (Elem element) = [element]
  flatten (List []) = []
  flatten (List (first:rest)) = flatten first ++ flatten (List (rest))
  main = print $ flatten $ List []
  </code></pre>
  
  <p>I wrote the above seen code in haskell. When I execute this with any other parameter, for example</p>
  
  <pre><code>main = print $ flatten $ List [Elem 1, Elem 2]
  main = print $ flatten $ Elem 1
  </code></pre>
  
  <p>It gives</p>
  
  <pre><code>[1, 2]
  [1]
  </code></pre>
  
  <p>respectively.</p>
  
  <p>It fails when I execute it with an empty List.</p>
  
  <pre><code>main = print $ flatten $ List []
  </code></pre>
  
  <p><strong>Error message</strong></p>
  
  <pre><code>No instance for (Show a0) arising from a use of `print'
  The type variable `a0' is ambiguous
  Possible fix: add a type signature that fixes these type variable(s)
  Note: there are several potential instances:
    instance Show Double -- Defined in `GHC.Float'
    instance Show Float -- Defined in `GHC.Float'
    instance (Integral a, Show a) =&gt; Show (GHC.Real.Ratio a)
      -- Defined in `GHC.Real'
    ...plus 23 others
  In the expression: print
  In the expression: print $ flatten $ List []
  In an equation for `main': main = print $ flatten $ List []
  </code></pre>
  
  <p><strong>Questions</strong></p>
  
  <ol>
  <li>Why does it fail and how can I fix this?</li>
  <li>Should I change my <code>NestedList</code> definition to accept an empty <code>List</code>? If so, how do I do that. Its quite confusing.</li>
  </ol>