
5 Dec
2007
5 Dec
'07
3:59 a.m.
Taral wrote:
On 12/4/07, Simon Marlow
wrote: do x <- newIVar let y = readIVar x writeIVar x 3 print y
(I wrote the let to better illustrate the problem, of course you can inline y if you want). Now suppose the compiler decided to evaluate y before the writeIVar. What's to prevent it doing that?
Look at the translation:
newIVar >>= (\x -> let y = readIVar x in writeIVar x 3 >> print y)
y can't be floated out because it depends on x.
y doesn't need to be floated out, just evaluated eagerly. Cheers, Simon