Simon Peyton-Jones wrote:
| class RandomGen g wher
| next :: g -> (Int, g)
| split :: g -> (g, g)
If we're fixing bugs in the part about Random.hs in the
Haskell'98 library report, we might as well fix the
following bug (spotted by John Hughes, but not present at
the bug page).
About "split", it says:
"The split operation allows one to obtain two distinct
random number generators. This is very useful in
functional programs (for example, when passing a random
number generator down to recursive calls), ..."
This is not enough. An early Hugs implementation of
"split" looked as follows:
split gen = (gen, someChangeTo gen)
Certainly, these two generators are *distinct*, but they are
not *independent*. This is useless in "passing a random
number generator down to recursive calls"; see what happens
when you split "gen1" twice:
gen1
/ \
gen1 gen2 -- once
/ | | \
gen1 gen2 gen2 gen3 -- twice
In fact, they will produce the *same* generator "gen2" on
both sides, which will create an undesired dependency
between the two recursive calls.
This "bug" in Hugs is fixed in the newest version, but it
was not really a bug in Hugs, but a bug in the report. The
report should say: "two *independent* generators".
The definition of independent might be: "two generators
gen1 and gen2 are independent if no "split"-path starting at
gen1 intersects with a "split"-path starting at gen2".
(In reality, this can never be the case because generators
have a bounded representation, but we might adapt the
definition to "split"-paths of reasonable length.)
Regards,
Koen.
--
Koen Claessen http://www.cs.chalmers.se/~koen
phone:+46-31-772 5424 e-mail:[EMAIL PROTECTED]
-----------------------------------------------------
Chalmers University of Technology, Gothenburg, Sweden