title: Haskell return lazy string from file IO
body: <p>Here I'm back again with a (for me) really strange behaviour of my newest masterpiece...</p>
  
  <p>This code should read a file, but it doesn't:</p>
  
  <pre><code>readCsvContents :: String -&gt; IO ( String )
  readCsvContents fileName = do
       withFile fileName ReadMode (\handle -&gt; do
            contents &lt;- hGetContents handle
            return contents
            )
  
  main = do
      contents &lt;- readCsvContents "src\\EURUSD60.csv"
      putStrLn ("Read " ++ show (length contents) ++ " Bytes input data.")
  </code></pre>
  
  <p>The result is</p>
  
  <pre><code>Read 0 Bytes input data.
  </code></pre>
  
  <p>Now I changed the first function and added a <code>putStrLn</code>:</p>
  
  <pre><code>readCsvContents :: String -&gt; IO ( String )
  readCsvContents fileName = do
       withFile fileName ReadMode (\handle -&gt; do
            contents &lt;- hGetContents handle
            putStrLn ("hGetContents gave " ++ show (length contents) ++ " Bytes of input data.")
            return contents
            )
  </code></pre>
  
  <p>and the result is</p>
  
  <pre><code>hGetContents gave 3479360 Bytes of input data.
  Read 3479360 Bytes input data.
  </code></pre>
  
  <p>WTF ??? Well, I know, Haskell is lazy. But I didn't know I had to kick it in the butt like this.</p>