<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 Neil,<br>That helped. Now the code looks better - I still feel a little bad about the way I repeat calls to line' though - I was thinking of using a partially applied function with (newX,newY) as the last parameter - but that'll make the code less readable.<br><br>line :: Point -&gt; Point -&gt; [Point]<br>line (xa,ya) (xb,yb) = line' (x1,y1) (x2,y2) deltax deltay ystep isSteep 0<br>&nbsp; where<br>&nbsp;&nbsp;&nbsp; isSteep = abs (yb - ya) &gt; abs (xb - xa)<br>&nbsp;&nbsp;&nbsp; (xa',ya',xb',yb') = if isSteep<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then (ya,xa,yb,xb)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else (xa,ya,xb,yb)<br>&nbsp;&nbsp;&nbsp; (x1,y1,x2,y2) = if xa' &gt; xb'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then (xb',yb',xa',ya')<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else
 (xa',ya',xb',yb')<br>&nbsp;&nbsp;&nbsp; deltax = x2 - x1<br>&nbsp;&nbsp;&nbsp; deltay = abs (y2 - y1)<br>&nbsp;&nbsp;&nbsp; ystep = if y1 &lt; y2 then 1 else -1<br><br><br>line' (x1, y1) (x2, y2) deltax deltay ystep isSteep error<br>&nbsp; | x1 == x2 = if isSteep then [(y1, x1)] else [(x1, y1)]<br>&nbsp; | isSteep =<br>&nbsp;&nbsp;&nbsp; (y1, x1) :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line' (newX, newY) (x2, y2) deltax deltay ystep isSteep newError<br>&nbsp; | otherwise =<br>&nbsp;&nbsp;&nbsp; (x1, y1) :<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; line' (newX, newY) (x2, y2) deltax deltay ystep isSteep newError<br>&nbsp; where newX = x1 + 1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempError = error + deltay<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newY, newError)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = if (2 * tempError) &gt;= deltax then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (y1 + ystep,
 tempError - deltax) else (y1, tempError)<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: arial,helvetica,sans-serif; font-size: 10pt;"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight: bold;">From:</span></b> Neil Mitchell &lt;ndmitchell@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> Tuesday, July 28, 2009 6:44:58 PM<br><b><span style="font-weight: bold;">Subject:</span></b> Re: [Haskell-cafe] Need feedback on my Haskell code<br></font><br>
Hi Kashyap,<br><br>My first suggestion would be to run HLint over the code<br><span>(<a target="_blank" href="http://community.haskell.org/%7Endm/hlint">http://community.haskell.org/~ndm/hlint</a>) - that will spot a few easy</span><br>simplifications.<br><br>Thanks<br><br>Neil<br><br>On Tue, Jul 28, 2009 at 2:04 PM, CK Kashyap&lt;<a ymailto="mailto:ck_kashyap@yahoo.com" href="mailto:ck_kashyap@yahoo.com">ck_kashyap@yahoo.com</a>&gt; wrote:<br>&gt; Hi Everyone,<br>&gt; I managed to write up the line drawing function using the following links -<br><span>&gt; <a target="_blank" href="http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html">http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html</a></span><br><span>&gt; <a target="_blank" href="http://rosettacode.org/wiki/Bresenham%27s_line_algorithm#Haskell">http://rosettacode.org/wiki/Bresenham%27s_line_algorithm#Haskell</a></span><br>&gt;<br>&gt; line :: Point -&gt; Point -&gt;
 [Point]<br>&gt; line (xa,ya) (xb,yb) = line' (x1,y1) (x2,y2) deltax deltay ystep isSteep 0<br>&gt; &nbsp; where<br>&gt; &nbsp;&nbsp;&nbsp; isSteep = abs (yb - ya) &gt; abs (xb - xa)<br>&gt; &nbsp;&nbsp;&nbsp; (xa',ya',xb',yb') = if isSteep<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then (ya,xa,yb,xb)<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else (xa,ya,xb,yb)<br>&gt; &nbsp;&nbsp;&nbsp; (x1,y1,x2,y2) = if xa' &gt; xb'<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then (xb',yb',xa',ya')<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else (xa',ya',xb',yb')<br>&gt; &nbsp;&nbsp;&nbsp; deltax = x2 - x1<br>&gt; &nbsp;&nbsp;&nbsp; deltay = abs (y2 - y1)<br>&gt; &nbsp;&nbsp;&nbsp; ystep = if y1 &lt; y2 then 1 else -1<br>&gt;<br>&gt;<br>&gt; line' :: Point -&gt; Point -&gt; Integer -&gt; Integer -&gt; Integer -&gt; Bool -&gt; Integer<br>&gt; -&gt; [Point]<br>&gt; line' (x1,y1) (x2,y2) deltax deltay ystep isSteep error =<br>&gt; &nbsp; if x1 == x2<br>&gt; &nbsp; then if isSteep then
 [(y1,x1)] else [(x1,y1)]<br>&gt; &nbsp; else<br>&gt; &nbsp;&nbsp;&nbsp; if isSteep<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then [(y1,x1)] ++ line' (newX,newY) (x2,y2) deltax deltay ystep<br>&gt; isSteep newError<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else [(x1,y1)] ++ line' (newX,newY) (x2,y2) deltax deltay ystep<br>&gt; isSteep newError<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; newX = x1 + 1<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tempError = error + deltay<br>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newY, newError) = if (2*tempError) &gt;= deltax then<br>&gt; (y1+ystep,tempError-deltax) else (y1,tempError)<br>&gt;<br>&gt;<br>&gt; Can someone please provide feedback on this? In terms of, how do I get more<br>&gt; Haskell'ism into it.<br>&gt;<br>&gt; Regards,<br>&gt; Kashyap<br>&gt;<br>&gt;<br>&gt;
 _______________________________________________<br>&gt; Haskell-Cafe mailing list<br>&gt; <a ymailto="mailto:Haskell-Cafe@haskell.org" href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><span>&gt; <a target="_blank" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a></span><br>&gt;<br>&gt;<br></div></div></div><br>

      </body></html>