The type of foldl is:<div>(b -&gt; a -&gt; b) -&gt; b -&gt; [a] -&gt; b</div><div><br></div><div>What do you expect &#39;a&#39; and &#39;b&#39; to be in your algorithm?<br><br><div class="gmail_quote">2009/11/8 michael rice <span dir="ltr">&lt;<a href="mailto:nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">Here&#39;s an (Fortran) algorithm for calculating an area, given  one dimensional<br>
arrays of Xs and Ys. I wrote a recursive Haskell function that works, and one using<br>FOLDL that doesn&#39;t. Why would Haskell be &quot;expecting&quot; (t, t) out of ((*) (xold-x) (yold+y))?<br><br>Michael<br><br>====================<br>
<br>   AREA = 0.0<br>   XOLD = XVERT(NVERT)<br>   YOLD = YVERT(NVERT)<br>   DO 10 N = 1, NVERT<br>           X = XVERT(N)<br>           Y = YVERT(N)<br>           AREA = AREA + (XOLD - X)*(YOLD + Y)<br>           XOLD = X<br>
           YOLD = Y<br>10
 CONTINUE<br><br>   AREA = 0.5*AREA<br><br>====================<br><br>area :: [(Double,Double)] -&gt; Double<br>area ps = abs $ (/2) $ area&#39; (last ps) ps<br>            where area&#39; _ [] = 0<br>                  area&#39; (x0,y0) ((x,y):ps) = (x0-x)*(y0+y) + area&#39; (x,y) ps<br>
<br><br><br>*Main&gt; let p = [(0.0,0.0),(1.0,0.0),(1.0,1.0),(0.0,1.0),(0.0,0.0)]<br>*Main&gt; area (last p) p<br>1.0<br>*Main&gt; <br><br>====================<br><br>area :: [(Double,Double)] -&gt; Double<br>area p = foldl (\ (xold,yold) (x,y) -&gt; ((*) (xold-x) (yold+y))) 0 ((last p):p)<br>
<br><br>Prelude&gt; :l area<br>[1 of 1] Compiling Main             ( area.hs, interpreted )<br><br>area.hs:29:40:<br>    Occurs check: cannot construct the infinite type: t =
 (t, t)<br>      Expected type: (t, t)<br>      Inferred type: t<br>    In the expression: ((*) (xold - x) (yold + y))<br>    In the first argument of `foldl&#39;, namely<br>        `(\ (xold, yold) (x, y) -&gt; ((*) (xold - x) (yold + y)))&#39;<br>
Failed, modules loaded: none.<br>Prelude&gt; <br><br></td></tr></tbody></table><br>

      <br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Eugene Kirpichov<br>Web IR developer, <a href="http://market.yandex.ru">market.yandex.ru</a><br>
</div>