Tim Bishop wrote:
>I am relatively new to Haskell, and I'm using Hugs 1.4.
>
>My my source of programming is Java, with the odd bit of basic thrown in
>for good measure.
>
>Now one of the first things I notice about Haskell is that there don't seem
>to be variables in the same sense that there are in other programming
>languages. I want to be able to store a value, or a set of values for use
>through-out various functions.
It sounds like you want global variables that you can alter as needed.
Functional languages frown on such things; in a functional language, a
function's behavior is controlled only by its arguments, and it produces
only its return value. This means if you call a function several times with
the same arguments, you are guaranteed to get back the same result. This
would not be the case if the function could modify global variables, and
alter its behavior based on their current values.
One approach to this is to define a tuple type that represents the current
state of these "global" variables, and pass it in and out of the functions
that need them. In other words, if a function needs to know the "state",
pass it in as an extra argument; if it also needs to modify the state, then
have it return the new value of the state (presumably in a tuple with
whatever value you really want the function to return).
Craig