title: Haskell. Matching pattern Problem. Cannot put in IO value of function with empty list "print $ note1 []" - failing to compile
body: <p>Haskell. Matching pattern Problem. Cannot put in IO value of function with empty list</p>
  <pre><code>print $ note1 []
  </code></pre>
  <p>failing to compile, but works fine in ghci ?!
  Also the <code>print $ note1 [1]</code> works fine and compiles fine too. The problem only with empty list:</p>
  <pre><code>print $ note1 []
  </code></pre>
  <p>(N.B. I am new in Haskell)
  I
  have a matching pattern function</p>
  <pre><code>note1          :: (Show a) =&gt; [a] -&gt; String
  note1 []       = &quot;Empty&quot;
  note1 (x:[])   = &quot;One&quot;
  </code></pre>
  <p>But <code>print $ note1 []</code> fails to compile, but perfectly works in ghci interpreter?!</p>
  <p>I am using stack 2.3.1 and ghc 8.8.3 on MacOS.</p>
  <p>This is the compilation error produced by compiler.</p>
  <pre><code>    /Users/admin1/Haskell/PROJECTS/orig1/src/Lib.hs:18:13: error:
      • Ambiguous type variable ‘a0’ arising from a use of ‘note1’
        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 15 instances involving out-of-scope types
          (use -fprint-potential-instances to see them all)
      • In the second argument of ‘($)’, namely ‘note1 []’
        In a stmt of a 'do' block: print $ note1 []
        In the expression:
          do putStrLn &quot;someFunc&quot;
             putStrLn $ show (1)
             putStrLn $ show $ length (&quot;a&quot; :: String)
             putStrLn $ show (length' &quot;a&quot;)
             ....   |
  18 |     print $ note1 []
  </code></pre>