title: How to modify a state monad?
body: <p>I use State Monad Transformer to manage global state like this</p>
  
  <pre><code>data State = State ...
  StateT State IO ()
  </code></pre>
  
  <p>And I use <code>amqp</code> to consume messages from RabbitMQ. The state will be modified according to messages received. The function has the type like</p>
  
  <pre><code>consumeMsgs :: Channel 
              -&gt; Text 
              -&gt; Ack 
              -&gt; ((Message, Envelope) -&gt; IO ())  -- ^ the callback function
              -&gt; IO ConsumerTag
  </code></pre>
  
  <p>Right now we can ignore other parameters but the third which is a callback function I will supply and where the modification happen.</p>
  
  <p>Because it's a mainly IO Monad, so I use this function as follows</p>
  
  <pre><code>consumeMsgs chan queue Rmq.Ack (flip evalStateT ssss . rmqCallback)
  </code></pre>
  
  <p>Here the <code>ssss</code> is the state I put in and I find that during the process of my callback function <code>rmqCallback</code> the state can be correctly modified. But, every time next callback happens the global state is the same as before the consumeMsgs is called or equal with <code>ssss</code>.</p>
  
  <p>I understand State Monad is just a process needing an initial state to put in and maintain the state during whole way but has nothing to do with the state out of Monad (am I missing something?),  so I count on MVar to hold and modify the state, and that works. I want to know it's there other way to handle this, maybe another Monad?</p>