[Haskell-cafe] Re: [Haskell] IVar
Simon Marlow
simonmarhaskell at gmail.com
Wed Dec 5 03:58:11 EST 2007
Jan-Willem Maessen wrote:
>> Consider this:
>>
>> 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? Nothing in
>> the Haskell spec, only implementation convention.
>
> Nope, semantics. If we have a cyclic dependency, we have to respect
> it---it's just like thunk evaluation order in that respect.
Ah, so I was thinking of the following readIVar:
readIVar = unsafePerformIO . readIVarIO
But clearly there's a better one. Fair enough.
Cheers,
Simon
More information about the Haskell-Cafe
mailing list