Re: [Haskell-cafe] random-fu confusion

2010-09-07 Thread James Andrew Cook
On Sep 7, 2010, at 10:21 AM, Alex Rozenshteyn wrote: > Okay, I figured the immutability bit out and I got the IORef example working, > but I can't get it to work with state. > > > put (pureMT 0) >>= runRVar flipCoin > > gives me two type errors: "No instance for (MonadState PureMT m)" and "No

Re: [Haskell-cafe] random-fu confusion

2010-09-07 Thread Alex Rozenshteyn
Okay, I figured the immutability bit out and I got the IORef example working, but I can't get it to work with state. > put (pureMT 0) >>= runRVar flipCoin gives me two type errors: "No instance for (MonadState PureMT m)" and "No instance for (RandomSource m ())" > runState $ put (pureMT 0) >>= r

Re: [Haskell-cafe] random-fu confusion

2010-09-07 Thread James Andrew Cook
A PureMT generator is immutable, so must be threaded through the monad in which you are sampling. There are RandomSource instances provided for a few special cases, including "IORef PureMT" in the IO monad. For example: main = do mt <- newPureMT src <- newIORef mt flips <- runRVar

[Haskell-cafe] random-fu confusion

2010-09-02 Thread Alex Rozenshteyn
I seem to be having confusion at the runRVar level of random-fu. I can't figure out how to use the Data.Random.Source.PureMT module to get a meaningful random source (I can't get my code to type-check). I wrote a [trivial] flipCoin function > flipCoin = uniform False True and am trying to fill in