title: What is the name of this Monad Stack function?
body: <p>I've got a bunch of stateful functions inside a State monad. At one point in the program there needs to be some IO actions so I've wrapped IO inside a StateT getting a pair of types like this:</p>
  
  <pre><code>mostfunctions :: State Sometype a
  toplevel :: StateT Sometype IO a
  </code></pre>
  
  <p>To keep things simple I don't want pass the IO context into the main set of functions and I would like to avoid wrapping them in the monad stack type. But in order to call them from the toplevel function I need something akin to a lift, but I'm not trying to lift a value from the inner monad. Rather I want to convert the state in the StateT monad into something equivalent in the State monad. To do this I've got the following:</p>
  
  <pre><code>wrapST :: (State Sometype a) -&gt; StateT Sometype IO a
  wrapST f = do s &lt;- get
                let (r,s2) = runState f s 
                put s2
                return r
  </code></pre>
  
  <p>This then get used to interleave things like the following:</p>
  
  <pre><code>toplevel = do liftIO $ Some IO functions
                wrapST $ Some state mutations
                liftIO $ More IO functions
                ....
  </code></pre>
  
  <p>It seems like a fairly obvious block of code so I'm wondering does this function have a standard name, and it is already implemented somewhere in the standard libraries? I've tried to keep the description simple but obviously this extends to pulling one transformer out of a stack, converting the wrapped value to the cousin of the transformer type, skipping the monads below in the stack, and then pushing the results back in at the end.</p>