Opened 9 years ago
Closed 5 years ago
#4218 closed bug (fixed)
System.Random is way too lazy
Reported by: | EyalLotem | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 7.10.1 |
Component: | libraries/random | Version: | 6.12.3 |
Keywords: | random stack overflow | Cc: | rrnewton, ekmett |
Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
Type of failure: | None/Unknown | Test Case: | |
Blocked By: | Blocking: | ||
Related Tickets: | 427, 7936 | Differential Rev(s): | |
Wiki Page: |
Description (last modified by )
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
Attachments (2)
Change History (20)
Changed 9 years ago by
Attachment: | TestRandomRs.hs added |
---|
Changed 9 years ago by
Attachment: | TestRandomIO.hs added |
---|
comment:1 Changed 9 years ago by
comment:2 Changed 9 years ago by
Description: | modified (diff) |
---|
comment:3 Changed 9 years ago by
Milestone: | → 6.14.1 |
---|
comment:4 Changed 9 years ago by
Milestone: | 7.0.1 → 7.0.2 |
---|
comment:5 Changed 9 years ago by
Milestone: | 7.0.2 → 7.2.1 |
---|
comment:6 Changed 8 years ago by
Owner: | set to rrnewton |
---|
comment:7 Changed 8 years ago by
Milestone: | 7.2.1 → 7.4.1 |
---|
comment:8 Changed 8 years ago by
Milestone: | 7.4.1 → 7.6.1 |
---|---|
Priority: | normal → low |
comment:9 Changed 7 years ago by
Milestone: | 7.6.1 → 7.6.2 |
---|
comment:10 Changed 5 years ago by
Cc: | rrnewton added |
---|---|
Component: | Compiler → libraries/random |
difficulty: | → Unknown |
Milestone: | 7.6.2 → 7.10.1 |
comment:12 Changed 5 years ago by
Cc: | ekmett added |
---|---|
Owner: | changed from rrnewton to ekmett |
Making Edward K owner, since it's a Core Libraries issue. Just a question of reviewing the offered patch!
Simon
comment:13 Changed 5 years ago by
Status: | patch → upstream |
---|
comment:14 Changed 5 years ago by
Related Tickets: | → 427, 7936 |
---|
The change makes sense to me.
I've closed out https://ghc.haskell.org/trac/ghc/ticket/7936, which was a duplicate of this issue to consolidate here (as this was the older bug report, but left https://ghc.haskell.org/trac/ghc/ticket/427 as it has a bit broader scope.
comment:15 Changed 5 years ago by
Resolution: | → fixed |
---|---|
Status: | upstream → closed |
comment:16 Changed 5 years ago by
Owner: | ekmett deleted |
---|---|
Resolution: | fixed |
Status: | closed → new |
Reopening to set to patch
state, so we don't lose this.
comment:17 Changed 5 years ago by
Status: | new → patch |
---|
Messed up formatting so attached another file