[Haskell-cafe] RE: [Haskell] line-based interactive program
Simon Marlow
simonmar at microsoft.com
Wed Jul 13 10:46:20 EDT 2005
On 08 July 2005 18:22, Olaf Chitil wrote:
> In fact, unsafeInterleaveIO shows up limitations of the IO monad.
> Without this strange primitive (what is actually unsafe about it?)
Just picking up on this point: unsafeInterleaveIO is so named because it
lets you write programs that don't obey the usual laws. For example:
main = do
r <- newIORef 0
a <- unsafeInterleaveIO $ readIORef r
b <- unsafeInterleaveIO $ do writeIORef r 42; return 0
print (a + b)
if you change (a + b) to (b + a), you get a different answer.
Cheers,
Simon
More information about the Haskell-Cafe
mailing list