[Haskell] Re: Global Variables and IO initializers

Keean Schupke k.schupke at imperial.ac.uk
Sun Nov 7 10:18:37 EST 2004

Adrian Hey wrote:

>I'm not at all convinced, having not seen or groked either the "before" or
>"after" code. Perhaps you could show how this would work with an even simpler
>example, the one that I posted concerning the use of oneShot to create a
>top level (I.E. exportable) userInit.
>AFAICS the only alternative to..
> userInit <- oneShot realInit
>is to export realInit, have users create their own userInit, and then pass
>that around as an argument to everything that might make use of userInit.
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.

By not exporting the constructors for the data type from
your module the 'user' will not be able to get at the contents.


More information about the Haskell mailing list