[Haskell-cafe] Re: [Haskell] Re: Haskell Digest, Vol 52, Issue 1
simonmarhaskell at gmail.com
Wed Dec 5 03:59:31 EST 2007
> On 12/4/07, Simon Marlow <simonmarhaskell at gmail.com> wrote:
>> 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.
More information about the Haskell-Cafe