haskell - Is there a `replicateM` function for the internal monad in a monad transformer? -


Suppose I have something like this:

  data environment = ... data MyState = ... data report = ... updatestate :: environment - & gt; Mistake - & gt; Myastat UpdateState = ... Report: Mystate - & gt; Report report = ... foo :: ReaderT environment (state MyState) report from foo = env & lt; - ask the state & lt; - Elevator mill newState = updateState env state lift $ put newState $ report return newstate   

What's in my head simulation of a time process in which I have parameters that environment < Will be stored in / code>, the dynamic state will be stored in Mistet and the information that I want to collect in each step of the simulation will be stored in Report .

Now, I do not want to run several steps of this simulation and get a list with it every time the report for the step

I usually call it ReaderT And used to pass the parameter in this way:

  foo :: Enviroment -> State Mistet Report   

Then I will do the following:

  Several steps :: int -> environment - & gt; State MyState [Report] manySteps n env = Repeat n $ (foo env)   

I'm confused with the type of lift and replicateM . What is a combination of a repeat code inside the transformer? state mestate

In the future, I will change the Readerty Environment (State Mistake) Report . Report to ReaderT environment (StateT MyState (Rand StdGen)) So this is right for this monster type :( Before getting things better is

Edit Do: as a side question - ReaderT Environment (State Mistake) Report ?

A solid example of replicateM here:

  Import Control.Monad Import Control.Monad.Reader Import Control.Monad.State Data Environment = E-Gets Show Data MyStat Get E = S Int Get Data Show Report = R string updateState :: Environment Show - & gt; MyState - & gt; MyState updateState (E step) (S val) = S $ val + move Report MyState :: - & gt; ! report (S val) = R (show Val) foo :: Reader T environment (state Maistet) Repo RT & the foo = env lt, - ask the state of & lt; - get - did not need to lift NewState = updateState env state keep newState - lift was not needed to return $ report newState ESM = runState (runReaderT) me  

Note that the reader has a monadestate pass-through example, so I removed "lift". Running foo returns once:

  * main & gt; (E10) (S5) FU (R "15", S15)   

I can run seven times in a row:

  * Main & gt; Run (E10) (S5) (Repeat M7 FU) ([R "15", R "25", R "35", R "45", R "55", R "65", R "75 "], S 75)   

What is the need for more clarification?

Comments