[Haskell] Re: Global Variables and IO initializers
ahey at iee.org
Sun Nov 7 07:36:54 EST 2004
On Sunday 07 Nov 2004 3:16 am, Benjamin Franksen wrote:
> Of course, the downside is that some of the functions (not many) now have
> one or two additional arguments. OTOH one could argue that this is in fact
> an advantage, as it makes all the dependencies crystal clear.
I wouldn't argue that :-)
> Surely this is just one example, and not a very complex one. Nevertheless,
> I am now less convinced that using global variables is in fact a good idea,
> however convenient it may seem at first.
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.
Maybe I'm missing something, but this doesn't seem very attractive to me
as a library writer (it means I must expose realInit and just trust
users to only use it once). It doesn't seem very attractive to users either
(considerably complicates their code and places the burden on them to
"get it right").
More information about the Haskell