
On Wed, 5 Sep 2007, Jonathan Cast wrote:
On Wed, 2007-09-05 at 20:37 +0200, Henning Thielemann wrote:
Can someone explain me, why there are arrays with mutable but boxed elements? I thought that boxing is only needed for lazy evaluation. However if I access an element of an array that is the result of a sequence of in-place updates, all updates must be executed in order to get the final value. That is, the first access to an element of such an array evaluates all elements of the array
I was imprecise here. With 'access' I meant an access to the array outside of the ST monad, that is on the result of runSTArray.
No. A mutable array is mutable only in a monad (IO or ST), and updates happen within that monad. But they don't evaluate the values in the array at all, either the old value or the new one. They just move pointers to expressions in the heap around.
I'll see, if I understand it. do writeArray arr 0 2 x <- readArray arr 0 writeArray arr 0 (x+x) If 'arr' is an STArray, the 'arr' will contain the unevaluated expression "2+2" as zeroth element and with type STUArray it will contain the evaluated "4" ?