Albert Lai: Thanks. I got the poit more or less; Each invocation creates a new IORef instance. UnsafePerformIO appears to generate a unique IORef that can be shared (sorry for my imperative vocabulary, I´m sill contaminated by al these evil languages ;). I tried with "usafePerformIO NewTVar v" but the program fails miserably in a memory fault. I finally did it well usign a IORef than contains the TVar: refcache =unsafePerformIO $ (do c <- atomically $ newTVar emptyFM newIORef c) and then dereferencing refcache in the IO Monad I get ever the same context no matter where i do it: do tvcache <- readIORef refcache atomically $ do finiteMap <- readTVar tvcache (useful code here at last)... --------------------- Who said that Haskell is difficult?. Jokes apart, STM is powerful. I will share the transactional cache when I have it tested. -----------referred message:------- Message: 1 Date: 12 May 2006 00:19:28 -0400 From: Albert Lai <trebla@vex.net> Subject: Re: [Haskell-cafe] Re: Haskell-Cafe Digest, Vol 33, Issue 9 To: haskell-cafe@haskell.org Message-ID: <4u3bffq3hr.fsf@shell.vex.net> Content-Type: text/plain; charset=us-ascii "Alberto G. Corona " <agocorona@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