Newbie question on "statefullness"

Andrew J Bromage ajb@spamcop.net
Mon, 12 Aug 2002 12:23:22 +1000


G'day all.

On Sun, Aug 11, 2002 at 07:03:04PM -0700, Alex Peake wrote:

> I am trying to implement a long-lived "accumulator"

How long is long?  Over what kind of code must it be preserved?
In what kind of code do you want to modify it and in what kind of
code do you want to read it?

By "what kind", I mean things like:

	- Is it just needed at the "top level" of your program?

	- Do you need I/O (or some other monadic construction) in the
	  same places as this accumulator or is it in different places?

	- What other "state" do you have?  How cleanly does
	  it separate from the rest of your code?

	- Is there some identifiable part of your program where
	  the "state" is "read only", some where it is "write only"
	  and/or some where it is "read/write"?

These are important considerations.  C has no automatic memory
management, so you must (usually) structure your code around the
lifetimes of your data.  Similarly, Haskell has no automatic state, so
you must (usually) structure your code around the scope of the state
that you intend to simulate.

Cheers,
Andrew Bromage