Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a `replicateM` function for the internal monad in a monad transformer?
    primarykey
    data
    text
    <p>Suppose I have something like this:</p> <pre><code>data Environment = ... data MyState = ... data Report = ... updateState :: Environment -&gt; MyState -&gt; MyState updateState = ... report :: MyState -&gt; Report report = ... foo :: ReaderT Environment (State MyState) Report foo = do env &lt;- ask state &lt;- lift get let newState = updateState env state lift $ put newState return $ report newState </code></pre> <p>What's in my head are simulations of a time process in which I have parameters that will be stored in <code>Environment</code>, the dynamical state will be stored in <code>MyState</code> and info I wish to collect in each time step of the simulation will be stored in <code>Report</code>.</p> <p>Now, I wan't to run many steps of this simulation and get a list with the reports for each time step. </p> <p>I usually did this without a <code>ReaderT</code> and used to pass the parameters like this:</p> <pre><code> foo :: Enviroment -&gt; State MyState Report </code></pre> <p>Then I would just do:</p> <pre><code> manySteps :: Int -&gt; Enviroment -&gt; State MyState [Report] manySteps n env = replicate n $ (foo env) </code></pre> <p>I'm getting confused with the types of <code>lift</code> and <code>replicateM</code>. Is there a combination that would replicate the <code>State MyState</code> monad inside the transformer?</p> <p>In the future I'll replace <code>ReaderT Environment (State MyState) Report</code> for <code>ReaderT Environment (StateT MyState (Rand StdGen)) Report</code> so it's better to get things right before having this monster type :(. </p> <p><strong>edit:</strong> as a side question - is there a better strategy than using <code>ReaderT Environment (State MyState) Report</code> ? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload