title: Read a file line by line
body: <p>I'm trying to read a file line by line, but I don't know how to stop when I reach the EOF.</p>
  
  <p>I have this code:</p>
  
  <pre><code>readWholeFile = do inputFile &lt;- openFile "example.txt" ReadMode
                  readALine inputFile
  
  readALine x = do y &lt;- hGetLine x
                   print y
                   readALine x
  </code></pre>
  
  <p>and it obviously always terminata raising an exception.</p>
  
  <p>How can I solve?</p>
  
  <p>Edit: exact error message is:</p>
  
  <pre><code>*** Exception: example.txt: hGetLine: end of file
  </code></pre>