title: Haskell IO: Reading the whole text file
body: <pre><code>import System.IO
  
  import Text.Printf
  
  kodable :: IO()
  kodable = do
      printf &quot;Please load a map : &quot;
      file &lt;- getLine
      mapFile &lt;- openFile file ReadMode
      let map = loadMap [] mapFile
      hClose mapFile
      printf &quot;Read map successfully! \n&quot;
      printf &quot;Initial:\n&quot;
      outputMap map
      
  loadMap :: [String] -&gt; FilePath -&gt; [String]
  loadMap map fp = do
      finished &lt;- hIsEOF fp
      new_map &lt;- if not finished
                 then map ++ [hGetLine fp]
                 else return ()
      loadMap new_map fp
      
  outputMap :: [String] -&gt; IO()
  outputMap (x) = printf &quot;%s\n&quot; x
  outputMap (x:xs) = do
      printf &quot;%s\n&quot; x
      outputMap xs
  </code></pre>
  <p>I am working on a project which need to load a map into the game first from a txt file, eg &quot;map.txt&quot;. The <strong>kodable</strong> is the main function.
  First, the game will ask the player to load a map. So, in that case, the player will input <strong>map.txt</strong>. Then, I am trying to use the function <strong>loadMap</strong> to recursively put the map into array of string and stored in <strong>map</strong>. Finally, I will use the function <strong>outputMap</strong> to output the map I have load.
  As I am still a beginner in Haskell, so I am having trouble in debugging this part.</p>