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