
9 Jan
2011
9 Jan
'11
11:16 a.m.
On Sun, Jan 09, 2011 at 05:55:41PM +0200, John Smith wrote:
Why does theStdGen require unsafePerformIO? I recompiled the Random module with
theStdGen :: IO (IORef StdGen) theStdGen = do rng <- mkStdRNG 0 newIORef rng
The implementations of a few functions needed to change slightly (to extract the IORef from IO), but no other type signatures needed changing, and nothing blew up.
With your definition, theStdGen is a computation that gives you a *new*, *different* IORef (containing yet another generator initialized with a seed of zero) every time you call it. The original definition with unsafePerformIO generates a single, global IORef which is accessed by every subsequent call to getStdGen. -Brent