[Haskell-cafe] IO in lists

Joachim Breitner mail at joachim-breitner.de
Tue Jan 16 11:01:55 EST 2007


you can also try with unsafeInterleaveIO, works like a charm, and you
really feel the laziness:

*Main> main
-- now entering “testq”

import System.IO.Unsafe

sequence' :: [IO a] -> IO [a]
sequence' (x:xs) = do 
	r  <- x;
	rs <- unsafeInterleaveIO (sequence' xs)
	return (r:rs)
main = do
	allChars <- sequence' $ repeat getChar
	let getChars = takeWhile (/= 'q') allChars
	print getChars

Unfortunately, this did not work:
	allChars <- sequence $ repeat $ unsafeInterleaveIO getChar
Probably because of something sequence is doing.


Joachim "nomeata" Breitner
  mail: mail at joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
  JID: joachimbreitner at amessage.de | http://www.joachim-breitner.de/
  Debian Developer: nomeata at debian.org

More information about the Haskell-Cafe mailing list