title: IO in Haskell not visible
body: <p>I have a little interactive game program. The interactive part looks like this,</p>
  <pre><code>main :: IO ()
  main = playGame newGame
    where
  
    playGame :: Game -&gt; IO ()
    playGame game = 
      do putStr $ show game
         putStr $ if gameOver game then &quot;Another game? (y or n) &gt; &quot; 
                                   else show (whoseMove game) ++ &quot; to play (row col) &gt; &quot;
         moveWords &lt;- fmap (words . fmap cleanChar ) getLine
         if stopGame game moveWords
           then return ()
           else playGame $ if gameOver game then newGame else makeMove game moveWords 
  </code></pre>
  <p>This works fine. It displays the game state, asks for the next move, applies that move to the state, displays the new state, etc.</p>
  <p>Then I saw a <a href="https://www.youtube.com/watch?v=Fk1KzABNm_U" rel="nofollow noreferrer">video</a> by <a href="https://stackexchange.com/users/7580/moss-collum">Moss Collum</a> in which he showed a <a href="https://github.com/moss/haskell-roguelike-challenge/blob/master/2-i-am-that-merry-wanderer-of-the-night/iatmwotk.hs" rel="nofollow noreferrer">game</a> that uses the following strategy for interacting with the user.</p>
  <pre><code>...
  userInput &lt;- getContents
  foldM_ updateScreen (12, 40) (parseInput userInput) where
  ...
  </code></pre>
  <p>I couldn't find a reference to <code>foldM_</code> but assuming it was some sort of <code>fold</code> I tried this. (I actually tried a number of things, but this seems clearest.)</p>
  <pre><code>main' :: IO ()
  main' = do
    moveList &lt;- fmap (map words . lines . map cleanChar) getContents 
    let states = scanl makeMove newGame moveList
    foldl (\_ state -&gt; putStr . show $ state) (return ()) states 
  </code></pre>
  <p>When I run it, I never get the game state printed out until after hitting end-of-file, at which point the correct final game state is printed. Before that, I can enter moves, and they are processed properly (according to the final game state), but I never see the intermediate states. (The idea is that lazy evaluation should print the game states as they become available.)</p>
  <p>I'd appreciate help understanding why I don't see the intermediate states and what, if anything, I can do to fix it.</p>
  <p>Also, after entering end-of-file (^Z on Windows) the program refuses to play again, saying that the handle has been closed. To play again I have to restart the program. Is there a way to fix that?</p>