On 2008 Oct 27, at 19:02, Rodney D Price wrote:
My old, deeply flawed mental picture had "iio" taking
the role of a pointer to a value.  My bright, shiny
new mental picture has "iio" acting just like a C
#define macro: every time I call "iio", I'm really
just writing "newIORef 0".  Is that what you're saying?


Sort of. What's really happening is that "newIORef" is an I/O action, just like "putStrLn", so will be executed every time it's used just as "putStrLn" is.

If you want to do it only once, you must do it only once and pass the resulting IORef around. (There is also a way to do "global variables", but it's rather unsafe and requires telling the compiler to not rewrite the initialization code.)

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell

Reply via email to