[Haskell-cafe] Using unsafePerformIO

Dinh Tien Tuan Anh tuananhbirm at hotmail.com
Mon Aug 1 07:24:49 EDT 2005

>So that's not safe, and thus it should be in the IO monad.

How can i handle a lazy list with IO monad.
For example, function

co (x:xs)
          ¦c ==1          = 1:co (xs)
          ¦c == 2         = 0:co (xs)
          where c = unsafePerformIO(f (x:xs))

will be written without unsafePerformIO:
    co' (x:xs) = do
                       c1 <- co' xs
                       c<- f (x:xs)
                       if (c==1)
                           then return 1:c1
                           else return 0:c1

AFAICS, co' does not do lazy evaluation, so wont print any element of the 
Can lazy evaluation be integrated with IO monad ?


Want to block unwanted pop-ups? Download the free MSN Toolbar now!  

More information about the Haskell-Cafe mailing list