[Haskell-cafe] state monad transformer that adds or combines state

Dennis Raddle dennis.raddle at gmail.com
Tue May 15 05:27:19 UTC 2018

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

deeperFunc :: Double -> M2 Double
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180514/9bd17c9f/attachment.html>

More information about the Haskell-Cafe mailing list