[Haskell] Re: Global Variables and IO initializers
benjamin.franksen at bessy.de
Sun Nov 7 08:57:55 EST 2004
On Sunday 07 November 2004 16:18, you wrote:
> 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.
Yes, whenever possible I would use this approach. Unfortunately, there are
libraries (or just modules) that need to do some IO action in order to
produce the (A)DT. In this case it _will_ make a difference how often you
call it. But then this is just how IO actions are by nature, isn't it?
More information about the Haskell