On Mon, 2008-10-27 at 17:02 -0600, Rodney D Price wrote:
My old, deeply flawed mental picture had "iio" taking the role of a pointer to a value.
Not so much flawed: you just need to realize that Haskell considers the sub-program `create a new IORef with contents 0 and return it' to be a perfectly good value, and when you say iio = newIORef 0 Haskell is perfectly happy to point iio at that sub-program. Your problem is distinguishing `program' from `value' and thinking that `value' means `result of program'. Haskell knows no such distinction.
My bright, shiny new mental picture has "iio" acting just like a C #define macro:
But this is a good intuition, too. Except without the weird syntax bugs. Also statically typed. And you can use recursion, etc. Other than that, `Haskell function = macro' isn't a bad (component of a) mental picture.
every time I call "iio", I'm really just writing "newIORef 0".
Write. So you say name = expression in Haskell when `name' is clearer in the contexts where it's used than `expression' is (or when expression needs to be recursive). jcc