Ryan gave some great advice about restructuring your program to do
what you want, but I wanted to give a small explanation of why that's
necessary.
2009/1/7 Phil pbeadl...@mail2web.com:
I want to be able to do:
Get_a_random_number
a whole load of other stuff
Get the next number as
I think I've got this now - thanks to you all for the superb advice!
The reason I cannot increment state inside main is because main is not a
State monad (it's an IO monad). Thus in order to use my State Monad, I have
execute inside a State monad as that the state is encapsulated in there.
I'll
On Thu, Jan 8, 2009 at 12:56 PM, Phil pbeadl...@mail2web.com wrote:
One more question on this - the other concern I had with the recursive list
approach was that although lazy evaluation prevents me generating numbers
before I 'ask' for them, I figured that if I was going to be asking for say
Hi,
I¹m a newbie looking to get my head around using the State Monad for random
number generation. I¹ve written non-monad code that achieves this no
problem. When attempting to use the state monad I can get what I know to be
the correct initial value and state, but can¹t figure out for the life
Hi,
I¹m a newbie looking to get my head around using the State Monad for random
number generation. I¹ve written non-monad code that achieves this no
problem. When attempting to use the state monad I can get what I know to be
the correct initial value and state, but can¹t figure out for the life
Hi Phil. First a quick style comment, then I'll get to the meat of
your question.
getRanq1 is correct; although quite verbose. A simpler definition is this:
getRanq1 = State ranq1
This uses the State constructor from Control.Monad.State:
State :: (s - (a,s)) - State s a
What it sounds like
On 2009 Jan 7, at 20:58, Phil wrote:
-- 124353542542 is just an arbitrary seed
main :: IO()
main = do
let x = evalState getRanq1 (ranq1Init 124353542542)
print (x)
You're throwing away the state you want to keep by using evalState
there. But you're also missing the point of