Maybe everytime you use 'cell' you tell haskell to create NEW cell. Try this: push' i cell = modifyIORef cell (++ [i]) main = do cell <- newIORef [] push' "x" cell {- push' 3 cell will be incorrect in this case -} push' "o" cell readIORef cell >>= return Why the original code porduces [(),()] but not [] I cannot undestand. 15.03.2012, 23:53, "gladstein@gladstein.com" <gladstein@gladstein.com>:
Why does the following program compile and produce the results it does? It seems like 3 and "x" got interpreted as the same type, (). Thanks in advance for your help.
import Data.IORef import System.IO.Unsafe
cell = unsafePerformIO $ newIORef []
push i = modifyIORef cell (++ [i])
main = do push 3 push "x" readIORef cell >>= return
*Main> :browse cell :: GHC.IORef.IORef [a] push :: a -> IO () main :: IO [a]
*Main> main [(),()]
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe