[Haskell-cafe] unsafeInerleaveIO and randomIO

Marc Weber marco-oweber at gmx.de
Tue Apr 17 03:17:44 EDT 2007


stefan has pointed me a nice version:

=============  =======================================================
randomInts :: IO [Int]
randomInts = randoms `fmap` newStdGen
	    
main = do
  ints <- randomInts
  print $ take 5 ints
===========  =========================================================

Anyway I'm curious why 

=============  =======================================================
module Main where
import Data.Char
import Control.Monad
import Random
import System.IO.Unsafe

randomInts :: IO [Int]
randomInts = unsafeInterleaveIO $ 
    sequence $ cycle [unsafeInterleaveIO randomIO]
	    
main = do
  ints <- unsafeInterleaveIO randomInts
  print $ take 5 ints
=============  =======================================================

doesn't return.
Where did I miss another unsafeInerleaveIO to make it lazy enough?
I still need a hint.

Marc


More information about the Haskell-Cafe mailing list