[Haskell-cafe] Using unsafePerformIO

Einar Karttunen ekarttun at cs.helsinki.fi
Mon Aug 1 09:50:30 EDT 2005

"Dinh Tien Tuan Anh" <tuananhbirm at hotmail.com> writes:
> 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

You might want to use unsafeInterleaveIO :: IO a -> IO a. 
It allows IO computation to be deferred lazily.

In the particular example 
co' (x:xs) = do c1 <- unsafeInterleaveIO (co' xs)
                c  <- f (x:xs)
                if (c==1) then return (1:c1) else return (0:c1)

- Einar Karttunen

More information about the Haskell-Cafe mailing list