[Haskell-cafe] Re: Haskell-Cafe Digest, Vol 33, Issue 9

Albert Lai trebla at vex.net
Fri May 12 00:19:28 EDT 2006

"Alberto G. Corona " <agocorona at gmail.com> writes:

> stmcache= newTVar 0

I will explain what this doesn't with an analogy.

import Data.IORef

notglobal = newIORef True

main = do a <- notglobal
          b <- notglobal
          writeIORef a False
          x <- readIORef b
          print x

To better show what's going on, I also provide this for contrast:

import Data.IORef
import System.IO.Unsafe

global = unsafePerformIO (newIORef True)

main = do x <- readIORef global
          print x
          writeIORef global False
          x <- readIORef global
          print x

More information about the Haskell-Cafe mailing list