Hi experts,

I fear I don't understand how to properly use *Data.IORef*.
I wrote the following code:


  1 -- Testing Data.IORef
  2 module Main where
  3
  4 import Data.IORef
  5
  6 bump :: IORef Int -> IO()
  7 bump theRef = do
  8     tmp <- readIORef theRef
  9     let tmp2 = tmp + 1
 10     writeIORef theRef tmp2
 11
 12 main = do
 13     let theValue = 1
 14     print theValue
 15     theValueRef <- newIORef theValue
 16     bump theValueRef
 17     return theValue


and got this, in ghci:


*Main> :load test2.hs
[1 of 1] Compiling Main             ( test2.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
1
*1*


I was expecting this:


*Main> :load test2.hs
[1 of 1] Compiling Main             ( test2.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
1
*2*


Can anyone help me understand what I'm doing wrong?


Thanks!
-db
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to