functions with states

Fergus Henderson fjh@cs.mu.oz.au
Thu, 4 May 2000 11:31:08 +1000


On 03-May-2000, Valery A.Khamenya <khamenya@module.ru> wrote:
> > The mathematical properties of functional
> > languages enable the compiler to do some very clever things.  A C
> > programmer would be very surprised to see the order in which Clean executes
> > the functions you type and if your static variable is dependant on calling
> > order you're going to get the wrong results.
> 
> I am ready for such surprises from language developed for parallel
> computation... More than that, existence of such a surprises is a good
> criterion for me: the language might be ripe for parallel
> computation.

Despite the name "Concurrent Clean", what Clean gives you is
actually deterministic parallelism, rather than the kind of
nondeterminism that you get in e.g. concurrent logic languages
or in concurrent imperative languages.

If you're looking for a functional language which supports
that kind of nondeterministic concurrent execution, then I
suggest you try Concurrent Haskell (which is supported by
ghc and also, to a limited extent, Hugs).

Perhaps if you gave a more concrete example of the problem
that you are trying to solve, we could suggest an alternative
solution.

> > The mathematically correct way is to have a variable, perhaps called state
> > (or even world :) that contains your static integer.  The state variable
> is
> > then another argument to your function and the function returns the new
> > state as well as whatever it returned before.
> 
> yes, I keep those principles in mind, but I can't _implement_ in Clean the
> functions like this.

With explicit state-passing?  Surely that is straight-forward.
Or do you mean that you can't implement them without explicitly passing
the state around?  That is by design.  See above.

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.