[Haskell] Re: Global Variables and IO initializers

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Fri Nov 5 08:23:40 EST 2004

Keean Schupke <k.schupke at imperial.ac.uk> writes:

> Why do want global variables?

Because they are more convenient than passing a state by hand.
They increase modularity by avoiding putting the fact that
a computation uses some global state in its type.

You don't want stdin/stdout/stderr?

Yes, *usually* it's a bad idea, but you are too idealistic.

> One of the advantages of a functional language is that a function
> only depends on it's arguments, not some 'hidden' state which makes
> debugging hard.

We are primarily talking about state used in IO actions. They already
depend e.g. on the state of the file system and the state of other
computers communicating via a network. Letting them depend on values
of a few global variables is not worse.

> Finally if something does IO (that is communicates with something
> stateful) that is not a state thread (due to the documented
> properties of the ST monad) it should be in the IO monad - thats
> what its there for.

The point is to avoid threading global state to IO actions manually.
Programming langages exist in order to conveniently write programs in,
not only to admire their beauty.

   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/

More information about the Haskell mailing list