[Haskell-cafe] global variables

Adrian Hey ahey at iee.org
Thu May 17 18:22:14 EDT 2007


Albert Y. C. Lai wrote:
> There is no reality about global variables. Global variables are 
> syntactic sugar for local variables. That is the reality we need to 
> think through. This syntactic sugar streamlines many practical programs 
> and is indeed valuable.

I agree that the use of the term "global variable" is both inaccurate
an highly emotive, which is why I don't like it. But even the term
I use ("top level mutable state") is not entirely accurate. The
mutable state is not at the top level, the mutable state is already
part of "the world" before main starts running.

What is top level are references to that state (IORefs, MVars etc).
As these are perfectly ordinary (I.E. *immutable*) Haskell values
there doesn't seem to be any obvious reason why they should not
exist at the top level. All that's missing is a semantically sound
mechanism to achieve this (such as the ACIO monad proposal).

Regards
--
Adrian Hey


More information about the Haskell-Cafe mailing list