<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>Thanks Sebastian,<br>Array/accumArray sounds like what I am looking for.<br><br>Int -&gt; ( a -&gt; a ) -&gt; [a] -&gt; [a]<br>approach, would it not be expensive on memory as well? Or is it just speed?<br><br>Regards,<br>Kashyap<br></div><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><br><div style="font-family: times new roman,new york,times,serif; font-size: 12pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Sebastian Sylvan &lt;sebastian.sylvan@gmail.com&gt;<br><b><span style="font-weight: bold;">To:</span></b> CK Kashyap &lt;ck_kashyap@yahoo.com&gt;<br><b><span style="font-weight: bold;">Cc:</span></b> haskell-cafe@haskell.org<br><b><span style="font-weight: bold;">Sent:</span></b> Monday, August 3, 2009
 3:14:47 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Haskell-cafe] Writing a pnm file<br></font><br>
<br><br>
<div class="gmail_quote">On Mon, Aug 3, 2009 at 6:38 AM, CK Kashyap <span dir="ltr">&lt;<a rel="nofollow" ymailto="mailto:ck_kashyap@yahoo.com" target="_blank" href="mailto:ck_kashyap@yahoo.com">ck_kashyap@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;" class="gmail_quote">
<div>
<div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">
<div style="font-family: times new roman,new york,times,serif; font-size: 12pt;">Thanks Sebastian,<br>ppm module is indeed very useful. So, I guess my question then just boils down to, how can I write a function to mimic the setPixel function -&gt;<br>
<br>Basically, a blank white image would look like this&nbsp; (as per ppm module)<br>[ <br>&nbsp;&nbsp; [ (255, 255, 255)&nbsp; , (255, 255, 255) , (255, 255, 255) ] ,&nbsp; -- 3 columns of row 1<br>&nbsp;&nbsp; [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255)&nbsp; ]&nbsp;&nbsp;&nbsp; --- 3 columns of row 2<br>
]<br><br>setPixel x y r g b when called like this - setPixel 0,0,255,0,0<br><br>[ <br>&nbsp;&nbsp; [ (255, 0, 0)&nbsp; , (255, 255, 255) , (255, 255, 255) ] ,&nbsp; -- 3 columns of row 1<br>&nbsp;&nbsp; [ (255, 255, 255) , (255, 255, 255) , (255, 255, 255)&nbsp; ]&nbsp;&nbsp;&nbsp; --- 3 columns of row 2<br>
]<br><br>What would be a good way to implement such a function?<br></div></div></div></blockquote>
<div>&nbsp;</div>
<div>Well you could start by writing a function like:</div>
<div>&nbsp;</div>
<div>adjustElem :: Int -&gt; ( a -&gt; a ) -&gt; [a] -&gt; [a]</div>
<div>&nbsp;</div>
<div>That would basically apply a function to a specific element in a list (indexed by the first parameter). Look at splitAt in Data.List, it may be useful. </div>
<div>Then you can use this in a nested way, by calling adjustElem to modify the row you're interested in, and the function you pass in to adjust that row would in turn call adjustElem on the specific pixel in that row).</div>

<div>&nbsp;</div>
<div>However, this may be very slow. If you don't care about speed it'll work fine, but if you really do want to build up an image by successive single-pixel modifications, you should consider first using an Array and accumArray, this will be much faster as internally accumArray can use a mutable array (while the external interface is still pure).</div>

<div>&nbsp;</div>
<div>&nbsp;</div>
<div>Sebastian</div></div>
</div></div></div><br>

      </body></html>