title: Keep track of the program variables in Haskell like imperative programs
body: <p>I'm having a hard time finding out how to make something change every time the user interacts with my program. It's hard to explain so here's an example (Haskell + wxhaskell):</p>
  
  <pre><code>simulate :: Int -&gt; Frame () -&gt; IO ()
  simulate qNr window = do
   fdata &lt;- readFile "qarchive"
   case (split (listTake (split fdata '\n') qNr 0) '#') of
    (qst:a:b:c:coralt:answer:x) -&gt; do
     -- GUI Controls Initialization (buttons,text,etc...) 
     nextButton &lt;- button window [text := "Next Question -&gt;", on command := set infoField [text := "Next Question"], position := pt 185 155]
     return ()
  
  main :: IO ()
  main = start gui
  
  gui :: IO ()
  gui = do
   window &lt;- frame [text := "Question program", clientSize := sz 640 480]
   headerText &lt;- staticText window [text := "Title Text", fontSize := 20, position := pt 5 5]
   simulate 0 window
   return ()
  </code></pre>
  
  <p>I want some widgets to change when the "Next Question" button is pressed. I want to change these widgets to some values I read from a file. How can I keep track of what the current question number is? I cannot actually increment questionNumber as a variable, since Haskell doesn't permit such things. I guess there's another way to do it.</p>
  
  <p>Example:</p>
  
  <pre><code>Initialize GUI
  Read data from file
  If button is pressed, increment question number by 1 and change widgets.
  </code></pre>
  
  <p>How do you tackle this kind of problem in a functional manner?</p>