title: Haskell file reading
body: <p>I have just recently started learning Haskell and I am having a lot of trouble trying to figure out how file reading works.</p>
  
  <p>For example, I have a text file "test.txt" containing lines with numbers:</p>
  
  <pre><code>32 4
  2 30
  300 5
  </code></pre>
  
  <p>I want to read each line and then evaluate each word and add them.</p>
  
  <p>Thus, I am trying to do something like this:</p>
  
  <pre><code>import System.IO
  import Control.Monad
  
  main = do
          let list = []
          handle &lt;- openFile "test.txt" ReadMode
          contents &lt;- hGetContents handle
          singlewords &lt;- (words contents)
          list &lt;- f singlewords
          print list
          hClose handle
  
  f :: [String] -&gt; [Int]
  f = map read
  </code></pre>
  
  <p>I know this is completely wrong, but I don't know how to use the syntax correctly at all.</p>
  
  <p>Any help will be greatly appreciated as well as links to good tutorials that have examples and explanation of code except <a href="http://learnyouahaskell.com/input-and-output" rel="noreferrer">this one</a> which I have read fully.</p>