[Haskell-cafe] Making a strict (non-lazy) GCL Interpreter

Ketil Malde ketil at malde.org
Tue Jun 30 05:30:19 EDT 2009

Hector Guilarte <hectorg87 at gmail.com> writes:

>   I need to randomly select ONE of the valid conditions and execute it's
> instruction. I know there is a Random Monad, but it returns an IO
> Int,

No, this is not right.  Values in the Random monad are computations
that rely on randomness, but they can produce values of arbitrary
type.  (The 'a' in 'Random a', no?)

> Is there anyway I can do some Random that doesn't involve IO? or any other
> solution?

Some options are:  

1.  Use the IO monad
2.  Use the Random monad
3.  Pass around a RandomGen explicitly
4.  Generate an infinite stream of random values, and pass that around 

I think option 2 is the nicest, but option 4 may work if the use of
randomness is limited.  No. 3 does the same as 2 (I presume, I never
looked) but with a lot more noise in your code, and no. 1 erases the
separation between real IO, and computations -- which IME includes a
lot of them -- that happen to depend on randomness (but require no
other IO).

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list