title: MonadParallel Instance for Rand
body: <p>I'm currently working with computations in <code>ReaderT r (Rand StdGen) a</code> which I would like to run in parallel. I've come across <a href="http://hackage.haskell.org/package/monad-parallel" rel="noreferrer">Monad Parallel</a> which seems like it will do what I want.</p>
  
  <p>There is already an instance of MonadParallel for <code>ReaderT</code> but I had to create my own for <code>Rand</code> from <a href="http://hackage.haskell.org/package/MonadRandom" rel="noreferrer">monad-random</a>. However, I'm not sure I've done it right. I'm not too familiar with parallel programming in Haskell, but I believe that there is an expectation that running compuations in parrallel should give the same value as when they're run normally. Because my instance of bindM2 for Rand uses <code>split</code> (and therefore gets a different set of random numbers from the same initial generator) this isn't the case for my instance.</p>
  
  <pre><code>instance P.MonadParallel (Rand StdGen) where
      bindM2 f ma mb = do
          split1 &lt;- getSplit
          split2 &lt;- getSplit
          let a = evalRand ma split1
          let b = evalRand mb split2
          a `par` b `pseq` f a b
  </code></pre>
  
  <p>While I feel that there is a case for ignoring this (the numbers are still random, right?) I also can't help feeling that I'm missing something. Is this okay or is there a better solution?</p>