TJ wrote:
> ----------------------------------------------------------
> module Global where
> 
> import Data.IORef
> 
> theGlobalVariable = newIORef []
> 
> testIt = do ref <- theGlobalVariable
>            original <- readIORef ref
>            print original
>            writeIORef ref [1,2,3]
>            new <- readIORef ref
>            print new
> ----------------------------------------------------------

Wrong.  You get a fresh new "variable" everytime you access
'theGlobalVariable'.  


> I've got a lot to learn about Haskell...

Well, for starters:

- there are no variables in ordinary Haskell,
- there are variables in the ST and IO monads, but dragging IO
  everywhere is burdensome and you don't want to do that,
- you can probably fake global variables using 'unsafePerformIO', and
  you definitely don't want to mess with that (yet),
- you need to understand monads in general, the State monad, the ST
  monad and the IO monad, and in exactly this order.
  
Whatever you're trying to do right now, just forget that there are
variables in BASIC and do it without mutable state.


-Udo
-- 
They laughed at Einstein.
They laughed at the Wright Brothers.
But they also laughed at Bozo the Clown.
        -- attributed to Carl Sagan

Attachment: signature.asc
Description: Digital signature

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

Reply via email to