Global variables?

Fergus Henderson
Mon, 3 Feb 2003 14:28:45 +1100

On 02-Feb-2003, Jon Cast <> wrote:
> Claus Reinke <> wrote:
> > It is the programmer's responsibility to verify that none of these
> > problems matter in the particular case of usage. Since many advances
> > in compiler technology tend to invalidate those verifications, it is
> > almost impossible to guarantee safety in such cases
> Even with sufficiently liberal use of {-# NOINLINE #-}?

Haskell Report, Appendix E (Compiler Pragmas):
"An implementation is not required to respect any pragma".

> > There you went.. into one of the many available traps in this
> > mine-field:
> > You argue that unallocated IORefs don't matter as long as "the" IORef
> > is allocated before it is dereferenced. But that's just part of the
> > problem - what about inlining globalVar, creating multiple IORefs?
> {-# NOINLINE globalVar #-} :)

What about creating two copies of globalVar, neither of them inlined?
A compiler could do that to improve performance on some architectures,
e.g. by allowing the function to be called via a short jump instruction
rather than a long jump instruction.

Fergus Henderson <>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.