[random-fu] sampleRVar with StdGen in RWS?

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-S...

It seems like you need your write-state to be a monoid in order to infer a `MonadRandom` instance. Based on your code, I'm guessing the compiler can't infer that. Have a look at https://hackage.haskell.org/package/MonadRandom-0.5.1.1/docs/Control-Monad-R... On 08/03/2018 07:31 AM, Sergiu Ivanov wrote:
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-S...
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- *Vanessa McHale* Functional Compiler Engineer | Chicago, IL Website: www.iohk.io http://iohk.io Twitter: @vamchale PGP Key ID: 4209B7B5 Input Output http://iohk.io Twitter https://twitter.com/InputOutputHK Github https://github.com/input-output-hk LinkedIn https://www.linkedin.com/company/input-output-global This e-mail and any file transmitted with it are confidential and intended solely for the use of the recipient(s) to whom it is addressed. Dissemination, distribution, and/or copying of the transmission by anyone other than the intended recipient(s) is prohibited. If you have received this transmission in error please notify IOHK immediately and delete it from your system. E-mail transmissions cannot be guaranteed to be secure or error free. We do not accept liability for any loss, damage, or error arising from this transmission

Hello Vanessa, MonadRandom from Control.Monad.Random does indeed have an RWST instance, but I'd like to stick with random-fu because of the long list of provided distributions, and the two seem incompatible : https://stackoverflow.com/a/13946470 I did try to force a very monoidal write-state: testRWS :: StdGen -> Int testRWS = fst . evalRWS work () where work = do tell "hello" sampleRVar $ uniform 1 10 I get <interactive>:2:25: error: • No instance for (MonadRandom (RWST () String StdGen Identity)) arising from a use of ‘work’ • In the first argument of ‘evalRWS’, namely ‘work’ In the second argument of ‘(.)’, namely ‘evalRWS work ()’ In the expression: fst . evalRWS work () which seems to be saying the same thing as before :-( - Sergiu Thus quoth Vanessa McHale on Fri Aug 03 2018 at 14:43 (+0200):
It seems like you need your write-state to be a monoid in order to infer a `MonadRandom` instance. Based on your code, I'm guessing the compiler can't infer that.
Have a look at https://hackage.haskell.org/package/MonadRandom-0.5.1.1/docs/Control-Monad-R...
On 08/03/2018 07:31 AM, Sergiu Ivanov wrote:
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-S...
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

It seems like the instance comes from http://hackage.haskell.org/package/random-source-0.3.0.6/docs/Data-Random-In... then, no? I only see an instance for `StateT` unfortunately. I suppose you could write an orphan instance for RWST if you really wanted to. On 08/03/2018 07:54 AM, Sergiu Ivanov wrote:
Hello Vanessa,
MonadRandom from Control.Monad.Random does indeed have an RWST instance, but I'd like to stick with random-fu because of the long list of provided distributions, and the two seem incompatible :
https://stackoverflow.com/a/13946470
I did try to force a very monoidal write-state:
testRWS :: StdGen -> Int testRWS = fst . evalRWS work () where work = do tell "hello" sampleRVar $ uniform 1 10
I get
<interactive>:2:25: error: • No instance for (MonadRandom (RWST () String StdGen Identity)) arising from a use of ‘work’ • In the first argument of ‘evalRWS’, namely ‘work’ In the second argument of ‘(.)’, namely ‘evalRWS work ()’ In the expression: fst . evalRWS work ()
which seems to be saying the same thing as before :-(
- Sergiu
Thus quoth Vanessa McHale on Fri Aug 03 2018 at 14:43 (+0200):
It seems like you need your write-state to be a monoid in order to infer a `MonadRandom` instance. Based on your code, I'm guessing the compiler can't infer that.
Have a look at https://hackage.haskell.org/package/MonadRandom-0.5.1.1/docs/Control-Monad-R...
On 08/03/2018 07:31 AM, Sergiu Ivanov wrote:
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-S...
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Thus quoth Vanessa McHale on Fri Aug 03 2018 at 15:06 (+0200):
It seems like the instance comes from http://hackage.haskell.org/package/random-source-0.3.0.6/docs/Data-Random-In... then, no? I only see an instance for `StateT` unfortunately.
Yes, that's what I see as well.
I suppose you could write an orphan instance for RWST if you really wanted to.
That's what I'll most probably do for my small project, but I was wondering whether it made sense to make a pull request to random-fu. To me, having a MonadRandom for both StateT and RWST seems very natural. - Sergiu
On 08/03/2018 07:54 AM, Sergiu Ivanov wrote:
Hello Vanessa,
MonadRandom from Control.Monad.Random does indeed have an RWST instance, but I'd like to stick with random-fu because of the long list of provided distributions, and the two seem incompatible :
https://stackoverflow.com/a/13946470
I did try to force a very monoidal write-state:
testRWS :: StdGen -> Int testRWS = fst . evalRWS work () where work = do tell "hello" sampleRVar $ uniform 1 10
I get
<interactive>:2:25: error: • No instance for (MonadRandom (RWST () String StdGen Identity)) arising from a use of ‘work’ • In the first argument of ‘evalRWS’, namely ‘work’ In the second argument of ‘(.)’, namely ‘evalRWS work ()’ In the expression: fst . evalRWS work ()
which seems to be saying the same thing as before :-(
- Sergiu
Thus quoth Vanessa McHale on Fri Aug 03 2018 at 14:43 (+0200):
It seems like you need your write-state to be a monoid in order to infer a `MonadRandom` instance. Based on your code, I'm guessing the compiler can't infer that.
Have a look at https://hackage.haskell.org/package/MonadRandom-0.5.1.1/docs/Control-Monad-R...
On 08/03/2018 07:31 AM, Sergiu Ivanov wrote:
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-S...
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (2)
-
Sergiu Ivanov
-
Vanessa McHale