13.5 Implementing simulation with monads
Monads are expected to pass through a kind of pipeline: a monad will be passed as an argument to a function and a similar monad will be returned as the value of the function. The functions must be designed to accept and return similar structures.
We’ll look at a monad-based pipeline that can be used for simulation of a process. This kind of simulation is sometimes called a Monte Carlo simulation. In this case, the simulation will create a Markov chain.
A Markov chain is a model for a series of potential events. The probability of each event depends only on the state attained in the previous event. Each state of the overall system had a set of probabilities that define the events and related state changes. It fits well with games that involve random chance, like dice or cards. It also fits well with industrial processes where small random effects can ”ripple through” the system, leading to effects that may not appear to be...