[Haskell-cafe] Re: [Haskell] Re: Global Variables and
Ben.Lippmeier at anu.edu.au
Mon Nov 8 01:16:29 EST 2004
Peter Simons wrote:
> [Global variables]
> Well, to be fair one has to say that they are still quite
> popular although people call them "singletons" and other
> cute things these days.
> Frankly, the idea that anyone would want to jump through
> hoops to add them to a purely functional language sounds
> bizarre to me. But by all means, as long as the compiler
> extension is disabled per default I won't mind. :-)
A singleton doesn't nessesarally have to be "mutable". The idea is that
the first time you use a singleton the object tied to that variable gets
created, then all subsequent calls to it share the same object.
A Constant Applicative Form (CAF) (an expression defined at top level
which has zero airity) in a pure functional language can be implemented
in the same way. If you implement it as a singleton, it doesn't have to
be created when its not needed.
All your top level library functions are also "global", you don't pass
them into every function that uses them do you?
"Mutable" global state is another matter. It's sometimes well used and
sometimes not. Just because you go and wrap a monad around it doesn't
make it less mutable.
More information about the Haskell-Cafe