
15 May
2018
15 May
'18
1:27 a.m.
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. In local computations, I may want to use some additional state. Is there a way to add a little extra state temporarily? Let's say I have data State1 = State1 StdGen type M1 = State State1 data State2 = State2 State1 Int type M2 = State State2 runM2 :: M2 a -> Int -> M1 a someFunc :: M1 Double someFunc = do r <- <compute something pseudorandomly> r2 <- runM2 (deeperFunc r) 3 <..etc..> deeperFunc :: Double -> M2 Double