[Haskell] Re: Global Variables and IO initializers

Adrian Hey ahey at iee.org
Sun Nov 7 16:46:15 EST 2004

On Sunday 07 Nov 2004 3:18 pm, Keean Schupke wrote:
> The way I would do it would be to have an init function that
> initialises an abstract data structure. Because the results of
> the init function are stateless and not in a global variable it
> does not matter if the user calls it twice.

I don't understand the relevance of this. In the example I gave
we're not talking about an abstract data structure and the init
function is not stateless.

I can assure you that for the intended applications of oneShot it
is vital that realInit is executed once at most, but the user must
have the freedom to execute userInit as many times as they need
(I.E. without the burden of having to keep track of whether or not
they've used it before).

So please, no more handwaving arguments about this kind of thing
being unnecessary, bad programming style, or whatever..

Please show me a concrete alternative in real Haskell code, other
than the IMO horrible alternative which I have already suggested.
If that's the only alternative available I will continue to use
the unsafePerformIO hack, I'm sorry to say :-(

Adrian Hey

More information about the Haskell mailing list