Hi,<br><br>I&#39;ve hit a brick wall trying to work out, what should be (and probably is!) a simple problem.<br><br>I have a StateT stack (1 State monad, 2 StateT transformers) which works fine and returns the result of the outer monad.  I thought I understood this fine, but perhaps not.  My understanding is that the result returned by the inner-most monad is always &#39;transformed&#39; by the outer monads and thus the result you get is that computed in the outer transformer.<br>
<br>The problem I have is now I&#39;d like not only to get the final state of the outer most transformer, but I&#39;d also like to know the final states of the the inner StateT and the inner State at the end of the computation (so that at a later point in time I can reinitialize a similar stack and continue with the same set of states I finished with).<br>
<br>So I figured I could have a separate (parent) State Monad (not part of this stack) that would store the final state of the sequence below.  I figured it couldn&#39;t be part of this stack, as one computation on the stack does not lead to one result in the parent State Monad; it is only the end states of the sequence I care about.<br>
<br>Anyway, currently I just have the stack evaluated as below.  Is there anyway from outside of the computation that I can interrogate the states of the inner layers?  The only way I can see to do this is inside the outer monad itself.  As I&#39;m not using the result I could use &#39;lift get&#39; and &#39;lift lift get&#39; to make the outer transformer return the two inner states as it&#39;s result.  I could ignore this result for the first (iterations-1) and bind a final iteration which uses replicateM instead of replicateM_.<br>
<br>This strikes me as pretty horrible tho!<br><br>So, in the example below if I want to modify the &#39;result&#39; function so it returns no only the outer state, but also the two inners states as a tuple (Double,Double,Double) is there an easier way of doing this?<br>
<br>result :: RngClass a =&gt; NormalClass b =&gt; a -&gt; b -&gt; MonteCarloUserData -&gt; Double<br>result initRngState initNormState userData = evalState a initRngState<br>                                                                           where  a = evalStateT b initNormState<br>
                                                                                       b = execStateT ( do replicateM_ (iterations userData) (mc userData)) 0<br><br><br>Any advice greatly appreciated!<br><br>Thanks,<br><br>
Phil.<br>