File: TestRandomIOs.hs

package info (click to toggle)
haskell-random 1.2.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: haskell: 2,696; makefile: 3
file content (21 lines) | stat: -rw-r--r-- 593 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- Test for ticket #4218 (TestRandomIOs):
-- https://ghc.haskell.org/trac/ghc/ticket/4218
--
-- Used to fail with:
--
-- $ cabal test TestRandomIOs --test-options="+RTS -M1M -RTS"
-- TestRandomIOs: Heap exhausted;

module TestRandomIOs where

import Control.Monad (replicateM)
import System.Random (randomIO)

-- Build a list of 5000 random ints in memory (IO Monad is strict), and print
-- the last one.
-- Should use less than 1Mb of heap space, or we are generating a list of
-- unevaluated thunks.
main :: IO ()
main = do
    rs <- replicateM 5000 randomIO :: IO [Int]
    print $ last rs