randomIO causing stack overflow ?

Remi Turk rturk at science.uva.nl
Mon Mar 2 17:16:58 EST 2009


On Mon, Mar 02, 2009 at 10:02:58PM +0000, Duncan Coutts wrote:
> This problem could probably be fixed by adjusting the definition of
> getStdRandom like:
> 
> getStdRandom :: (StdGen -> (a,StdGen)) -> IO a
> getStdRandom f = atomicModifyIORef theStdGen $! (swap . f)
>   where swap (v,g) = g `seq` (g,v)
> 
> Though even that may not do it. The StdGen data and stdNext functions
> may not be strict enough.
> 
> data StdGen = StdGen Int32 Int32
> 
> It's not strict in the Int32 fields. I doubt that it needs to be so
> lazy.

If I was right a few years ago, making getStdRandom more strict
is indeed enough, although it does change the behaviour of

    x <- randomRIO undefined

which probably noone cares about anyway.

There is also already a ticket for this and another problem:
http://hackage.haskell.org/trac/ghc/ticket/427

Groeten, Remi


More information about the Libraries mailing list