Global variables?

Jon Cast
Sun, 02 Feb 2003 21:06:13 -0600

Andrew J Bromage <> wrote:
> G'day all.

> On Fri, Jan 31, 2003 at 01:54:26PM -0600, Jon Cast wrote:

> > Otherwise, though, see my other post on this subject:
> > unsafePerformIO will perform its action when the variable is
> > accessed, so you can't write a Haskell program which differentiates
> > between what any compiler actually does and running the variable
> > allocations before main.

> As has been pointed out, there is no language requirement for a
> Haskell implementation to be "fully lazy".  In particular, it is
> technically possible for an implementation to garbage collect
> globalVar and re-evaluate it on the next call.

So, the technique is implementation-dependent.  Since Hughes'
recommendation is equally non-portable, I don't see this as a serious
problem in this case.

> Haskell 2 should probably have a pragma controlling this.

IMO, that would be a good idea :)

> Cheers,
> Andrew Bromage