title: Not typed empty list : Haskell
body: <p>I just tried to write the simplest maybe function I could imagine in Haskell, and got this error message. And magically it only appears, when I try to evaluate myHead for an empty list. What did I do wrong?</p>
  
  <pre><code>module Main 
    where
  
  myHead :: [a] -&gt; Maybe a
  myHead [] = Nothing
  myHead (x:_) = Just x
  
  main = do
  print (myHead [])
  </code></pre>
  
  <p>When I run it from a file, I get this output :</p>
  
  <pre><code>main.hs:15:1: error:
    • Ambiguous type variable ‘a0’ arising from a use of ‘print’
      prevents the constraint ‘(Show a0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘a0’ should be.
   These potential instances exist:
     instance Show Ordering -- Defined in ‘GHC.Show’
     instance Show Integer -- Defined in ‘GHC.Show’
     instance Show a =&gt; Show (Maybe a) -- Defined in ‘GHC.Show’
      ... plus 22 others
       ...plus 12 instances involving out-of-scope types
      (use -fprint-potential-instances to see them all)
   • In a stmt of a 'do' block: print (myHead [])
    In the expression: do { print (myHead []) }
    In an equation for ‘main’: main = do { print (myHead []) }
    &lt;interactive&gt;:3:1: error:
     • Variable not in scope: main
     • Perhaps you meant ‘min’ (imported from Prelude)
  </code></pre>