#4218: System.Random is way too lazy
--------------------------------------+-------------------------------------
    Reporter:  EyalLotem              |        Owner:              
        Type:  bug                    |       Status:  new         
    Priority:  normal                 |    Milestone:              
   Component:  Compiler               |      Version:  6.12.3      
    Keywords:  random stack overflow  |     Testcase:              
   Blockedby:                         |   Difficulty:              
          Os:  Unknown/Multiple       |     Blocking:              
Architecture:  Unknown/Multiple       |      Failure:  None/Unknown
--------------------------------------+-------------------------------------
Description changed by igloo:

Old description:

> randomRs is too lazy, generates lists of large lazy-state thunks, rather
> than lists of strict values.
>
> Test program is attached.
>
> Also, randomIO is too lazy, and builds up huge thunks. Using (randomIO
> >>= evaluate) is fine, however.
>
> Fails with stack overflow:
>   rs <- replicateM 1000000 evaluate :: IO [Int]
>   print $ last rs
>
> Works:
>   rs <- replicateM 1000000 (evaluate =<< randomIO) :: IO [Int]
>   print $ last rs

New description:

 randomRs is too lazy, generates lists of large lazy-state thunks, rather
 than lists of strict values.

 Test program is attached.

 Also, randomIO is too lazy, and builds up huge thunks. Using (randomIO >>=
 evaluate) is fine, however.

 Fails with stack overflow:
 {{{
   rs <- replicateM 1000000 evaluate :: IO [Int]
   print $ last rs
 }}}
 Works:
 {{{
   rs <- replicateM 1000000 (evaluate =<< randomIO) :: IO [Int]
   print $ last rs
 }}}

--

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4218#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to