<div class="gmail_quote">
<div>I want to say thanks to everyone who responded to my&nbsp;mutable array post.&nbsp; I&#39;m going to&nbsp;work through and experiment with all the comments people posted.&nbsp; It might take me a while.<br>&nbsp;<br>Luke Palmer wrote:<br></div>

<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<div><br></div>Hmm, how big is the array? &nbsp; If it&#39;s pretty big, that&#39;s<br>understandable. &nbsp;Frankly, it&#39;s because foldl sucks: I have never seen<br>a reason to use it. &nbsp;You should be using the strict variant foldl&#39;<br>
here. &nbsp;(I don&#39;t think there is a foldl1&#39;). &nbsp;And that will get rid of<br>your big function calc_max_2d_elem.<br>
<div><br></div></blockquote></div>
<div style="TEXT-ALIGN: left"><br>&nbsp;</div>
<div style="TEXT-ALIGN: left">I should have mentioned that I&#39;m working with a 2D array that is 1024 x 1024.&nbsp; Eventually, this code will have to work with arrays that are much larger.&nbsp; (For fun I write image processing and fractal &quot;art&quot; programs.)&nbsp; I replaced the foldl1 with foldl1&#39;.&nbsp; Unfortunately, I still get a stack overflow.&nbsp;&nbsp;&nbsp;</div>

<div>&nbsp;</div>
<div>Chaddaï Fouché wrote:</div>
<div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>Sorry but none of those propositions change the heart of the problem :<br>the list of elements is totally produced before she can be consumed<br>due to the strict monadic (IO or ST) nature of getElems. Thus you get<br>
an extraordinary waste of memory as well as resources...</div></blockquote>
<div><font face="arial,sans-serif"></font>&nbsp;</div>
<div><font face="arial,sans-serif"></font>&nbsp;</div>
<div><font face="arial,sans-serif">This is interesting.&nbsp; I&#39;ve been programming in Concurrent Clean for a while.&nbsp; Instead of monads, Clean supports unique types for mutable arrays and IO.&nbsp; In Clean, I can write code that iterates through a&nbsp;mutable array by converting it to a lazy list.&nbsp; This is&nbsp;convenient because I can use all the nice list processing functions that are available.</font></div>

<div>&nbsp;</div>
<div>Changing the subject slightly, I once wrote code in Concurrent Clean that filtered a file that was larger than the available memory on my PC.&nbsp; I did this by&nbsp;creating a function that returned the contents of the original file as a lazy list.&nbsp; Then, I&nbsp;created functions to process the list and write&nbsp;the processed&nbsp;list to&nbsp;a results&nbsp;file.&nbsp;&nbsp;The code was not&nbsp;imperative at all.&nbsp;&nbsp;The function that wrote the results file forced the evaluation of the lazy list.&nbsp; As the lazy list was consumed, the contents of the original file were read.&nbsp; Is this possible with Monads in Haskell?&nbsp; Based on your comments, I suspect that in Haskell, one would have to explicitly code a loop that reads a portion of the original file, processed it, and&nbsp;writes a portion of the results file, over and over.&nbsp;</div>

<div>&nbsp;</div>
<div>By the way, if anyone wants to see it, I can post some Clean code that demonstrates the file processing I described.&nbsp; Clean&#39;s syntax is very similar to Haskell&#39;s.</div>
<div>&nbsp;</div>
<div>Thanks,</div>
<div>&nbsp;</div>
<div>Jeff</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div></div>