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 igloo)

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)

TestRandomRs.hs (338 bytes) - added by EyalLotem 9 years ago.
TestRandomIO.hs (265 bytes) - added by EyalLotem 9 years ago.

Download all attachments as: .zip

Change History (20)

Changed 9 years ago by EyalLotem

Attachment: TestRandomRs.hs added

Changed 9 years ago by EyalLotem

Attachment: TestRandomIO.hs added

comment:1 Changed 9 years ago by EyalLotem

Messed up formatting so attached another file

comment:2 Changed 9 years ago by igloo

Description: modified (diff)

comment:3 Changed 9 years ago by igloo

Milestone: 6.14.1

comment:4 Changed 9 years ago by igloo

Milestone: 7.0.17.0.2

comment:5 Changed 9 years ago by igloo

Milestone: 7.0.27.2.1

comment:6 Changed 8 years ago by rrnewton

Owner: set to rrnewton

comment:7 Changed 8 years ago by igloo

Milestone: 7.2.17.4.1

comment:8 Changed 8 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:9 Changed 7 years ago by igloo

Milestone: 7.6.17.6.2

comment:10 Changed 5 years ago by thomie

Cc: rrnewton added
Component: Compilerlibraries/random
difficulty: Unknown
Milestone: 7.6.27.10.1

comment:11 Changed 5 years ago by thomie

Status: newpatch

The first issue (randomRs) was fixed with #8704.

I fixed the second issue (randomIO) here: https://github.com/haskell/random/pull/8

Last edited 5 years ago by thomie (previous) (diff)

comment:12 Changed 5 years ago by simonpj

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 thoughtpolice

Status: patchupstream

comment:14 Changed 5 years ago by ekmett

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 thomie

Resolution: fixed
Status: upstreamclosed

comment:16 Changed 5 years ago by thoughtpolice

Owner: ekmett deleted
Resolution: fixed
Status: closednew

Reopening to set to patch state, so we don't lose this.

comment:17 Changed 5 years ago by thoughtpolice

Status: newpatch

comment:18 Changed 5 years ago by ekmett

Resolution: fixed
Status: patchclosed

Shipped in random 1.1.

Note: See TracTickets for help on using tickets.