title: Haskell - Printing and returning a state at the same time
body: <p>I am writing a Brainf*ck Interpreter in Haskell.</p>
  
  <p>I am trying to print <code>(chr (fromEnum $ getMem state))</code> which is just a conversion of a Word8 to Char.
  Then I want to return a new state after the printing in a particular case which is</p>
  
  <pre><code>    '.' -&gt; do hPutChar stdout (chr (fromEnum $ getMem state))
              hFlush stdout
              return state { prog_pointer = prog_pointer state}
  </code></pre>
  
  <p>I get this error message</p>
  
  <pre><code>The function `hPutChar' is applied to six arguments,
  but its type `Handle -&gt; Char -&gt; IO ()' has only two
  
  In a stmt of a 'do' block:
    hPutChar
      stdout
      (chr (fromEnum $ getMem state))
      hFlush
      stdout
      return
      (state {prog_pointer = prog_pointer state})
  </code></pre>
  
  <p>with this code</p>
  
  <pre><code>iterateBF :: BFState -&gt; IO BFState
  iterateBF state = case (program state !! prog_pointer state) of
      --some more cases here--
      '.' -&gt; do hPutChar stdout (chr (fromEnum $ getMem state))
              hFlush stdout
              return state { prog_pointer = prog_pointer state}
  </code></pre>
  
  <p>I cant seem to figure out why I am getting this error.</p>
  
  <p>After leftaroundabout and sabauma's comments, i edited my code to be</p>
  
  <pre><code>iterateBF :: BFState -&gt; IO BFState
  iterateBF state = case (program state !! prog_pointer state) of
      --some more cases here--
      '.' -&gt; do hPutChar stdout (chr (fromEnum $ getMem state))
             hFlush stdout
             return state { prog_pointer = prog_pointer state}
  </code></pre>
  
  <p>using only spaces this time.</p>
  
  <p>However, I get <code>parse error on input 'hFlush'</code></p>
  
  <p>Anyone know why?</p>