> I guess you would end up with nearly the same code (unless I overlook
> an obvious alternative in which case I would love to see the simple and
> straightforward solution ;-). Let's be concrete: say you need n
> Integers within range (l, r), m Ints and p Doubles. Using a monad-based
> approach one writes
> 
>       ...
>       mis <- accumulate [ randomInteger (l, r) | i <- [1 .. n] ]
>       is  <- accumulate [ randomInt | i <- [1 .. m] ]
>       ds  <- accumulate [ randomDouble | i <- [1 .. p] ]
>       return (mis, is, ds)
> 
> What's your solution based on an [Int] list of random numbers?
First: I had forgotten that what the Random module actually
gives you is [Integer], not [Int], but the same reasoning
applies.

Well, you naturally need functions that convert a list of
[Integer] to what you need.  I'm not at all against such functions,
and I think they should be included, e.g.
  toDouble :: [Integer] -> [Double]
  toInt :: [Integer] -> [Int]
etc.  So I might write
  let mis = take n (random ss1)
      is  = take n (toInt (random ss2))
      ds  = take n (toDouble (random ss3))
  in  ...
where ss1, ss2, ss3 are the seeds.  You can get them from an initial
call to randomIO or use some known values if you need to repeat the sequence.

I think using monads, and specially a powerful one like IO, everywhere is
a mistake.  I can't see the need for most uses of random numbers.

     -- Lennart


Reply via email to