Global variables

Yitzchak Gale gale at
Thu Feb 1 05:13:48 EST 2007

The trick of controlling allocation of external
resources by using NOINLINE, unsafePerfromIO,
and IORef to create global variables has become
an indispensable technique in Haskell. It seems to
work well enough with most current compilers.

However, it is well known that the semantics of
NOINLINE are not sufficient to guarantee that this
is safe. In principle, the runtime is permitted to
GC and reinstantiate these things at any time.

Also, it would be nice if we could have a
guarantee that global constants are not instantiated
until first use. That would allow us to skip the
IORef in some cases.

I think this issue needs to be addressed in Haskell'.
(If it has already, please accept my apologies.)
Since NOINLINE has more general use, perhaps
there should be a new pragma for this purpose.


More information about the Haskell-prime mailing list