<div dir="ltr"><div>I find myself using the state and exception monads at large scale in my programs. For instance I often keep a pseudorandom generator as the state, and use exception handling.<br></div><div><br></div><div>In local computations, I may want to use some additional state. Is there a way to add a little extra state temporarily?</div><div><br></div><div>Let's say I have <br></div><div><br></div><div>data State1 = State1 StdGen</div><div><br></div><div>type M1 = State State1</div><div><br></div><div>data State2 = State2 State1 Int</div><div><br></div><div>type M2 = State State2</div><div><br></div><div>runM2 :: M2  a -> Int -> M1 a<br></div><div><br></div><div>someFunc :: M1 Double<br></div><div>someFunc = do</div><div>  r <- <compute something pseudorandomly></div><div>  r2 <- runM2 (deeperFunc r) 3</div><div>  <..etc..><br></div><div><br></div><div>deeperFunc :: Double -> M2 Double</div><div><br></div></div>