
On Sat, 2 Feb 2008, [ISO-8859-7] Jeff รถ wrote:
Hello,
I'm trying to write code that will take a mutable 2D array and normalize it by dividing all elements by the largest element.
Are you sure you need the arrays to be mutable? Maybe it's fast enough to do the copying - it's significantly easier anyway. If all operations run over the whole array, like the normalization, then it's not much a matter speed, but only a matter of memory. That is you need the double amount of memory, because the data can be processed and copied forth and back. You can even reduce this further, if you can come up with an optimizer fusion framework. With immutable arrays you can easily implement let xm = maximum (Array.elems arr) in fmap (/xm) arr Ok, better use the strict "maximum'" proposed by others in this thread.