
Of course, I used unsafePerformIO in an unsafe way!
I'm thinking about a way to make unsafePerformIO safe.
Therefore the compiler can't do any transformation the ghc does and I want
to locate these transformations.
----- Original Message -----
From: "Simon Marlow"
Consider the following program:
--------------------------------- {-# NOINLINE b #-}
b x = if even x then unsafePerformIO getChar else bot
bot = bot
main = do putChar (b 4) putChar (b 6)
-----------------------------
when you compile the programm with the options: -O0 and execute the program you get:
test ab (That's the input) ab (That's the ouput)
when you compile the programm with the options: -O1 -fno-cse you get:
test ab aa
You are using unsafePerformIO in an unsafe way. The meaning of your program depends on whether the compiler implements full laziness or not, which is a decision left entirely up to the compiler implementor. If you want to write portable code, don't use unsafePerformIO in this way. What exactly is it you're trying to achieve? Perhaps we can suggest a better solution. Cheers, Simon