[Haskell-cafe] [random-fu] sampleRVar with StdGen in RWS?

Sergiu Ivanov sivanov at colimite.fr
Fri Aug 3 12:31:54 UTC 2018


Dear Café,

I would like to use random-fu to do some pseudo-random simulations for a
given StdGen (so that I can run the same simulation multiple times, if
needed).

The following works:

  testState :: StdGen -> Int
  testState = evalState (sampleRVar $ uniform 1 10)

The following doesn't:

  testRWS :: StdGen -> Int
  testRWS = fst . evalRWS (sampleRVar $ uniform 1 10) ()
  
I get

  <interactive>:2:26: error:
  • No instance for (MonadRandom (RWST () b0 StdGen Identity)) arising from a use of ‘sampleRVar’
  • In the first argument of ‘evalRWS’, namely ‘(sampleRVar $ uniform 1 10)’
  In the second argument of ‘(.)’, namely ‘evalRWS (sampleRVar $ uniform 1 10) ()’
  In the expression: fst . evalRWS (sampleRVar $ uniform 1 10) ()

Indeed, I do see a MonadRandom instance for StateT, but none for RWST [0].

Is there a reason to not have a MonadRandom instance for RWST?

Am I looking in the wrong place?

-
Sergiu

[0] https://hackage.haskell.org/package/random-source-0.3.0.6/docs/Data-Random-Source.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180803/4a0c19d2/attachment.sig>


More information about the Haskell-Cafe mailing list