title: Game loop with IO in Haskell
body: <p>I'm trying to write a very simple game in Haskell.
  I have this loop which is the last part, and where I don't really know what to do. Of course it is a loop, so it has to run itself.</p>
  
  <pre><code>gameLoop :: User -&gt; IO ()
  gameLoop initUser = displayPosition initUser &gt;&gt; gameLoop (applyAction initUser)
    where
      applyAction :: UserAction
      applyAction = maybe id (unsafePerformIO (fmap getUserAction getLine))
  </code></pre>
  
  <p><code>getUserAction :: String -&gt; Maybe UserAction</code> is a function that looks up a string in a map and returns a <code>UserAction :: User -&gt; User</code>. Then I do some ugly unpacking (<code>unsafePerformIO</code>), which I don't know to circumvent.</p>
  
  <p>I thought this should run, because my type seems to be correct, but it still doesn't.</p>
  
  <p>It says:</p>
  
  <pre><code>maybe is applied to too few arguments  AND
  couldn't match a1 -&gt; a0 -&gt; a0 with actual type Maybe UserAction, because unsafePerformIO is applied to too few arguments.
  </code></pre>
  
  <p>I don't understand these errors. Can anybody explain how to solve these last problems, or how to get rid of <code>unsafePerformIO</code>?</p>