<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Hi,<br>
    <br>
    thanks for your answers. I'm exercising with different programming
    techniques, so the use of an accumulator was intentional although
    not necessary. As Vlad said, my mistake was the stronger binding of
    the function application. Sigh, ...<br>
    <br>
    Thank you all again.<br>
    <br>
    Alex<br>
    <br>
    On 10/18/2011 02:48 PM, Lorenzo Bolla wrote:
    <blockquote
cite="mid:CADjgTRzTafiyMwFuNd8UYyMw7Djxvf-7SNespN8W5hKSm7mhUA@mail.gmail.com"
      type="cite">Hi,<br>
      <br>
      <div class="gmail_quote">On Tue, Oct 18, 2011 at 1:19 PM,
        Alexander Raasch <span dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:info@alexraasch.de">info@alexraasch.de</a>&gt;</span>
        wrote:<br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          padding-left: 1ex;">
          Hi,<br>
          <br>
          so I wrote this function to add two vectors represented as
          lists:<br>
          <br>
          add a b = add' a b [] where<br>
             add' [] [] s = s<br>
             add' (a:as) (b:bs) s ++ [a+b]<br>
          <br>
        </blockquote>
        <div><br>
        </div>
        <div>I think something mangled your function, as this is not
          valid Haskell code.</div>
        <div><br>
        </div>
        <div>Anyway, I tried to rewrite your function.</div>
        <div>The first version works as expected; the second gives
          reversed output.</div>
        <div>Note that there is no need for the accumulator "s".</div>
        <div>
          <div><br>
          </div>
          <div>add a b = add' a b</div>
          <div>        where add' [] [] = []</div>
          <div>              add' (a:as) (b:bs) = [a+b] ++ (add' as bs)</div>
        </div>
        <div><br>
        </div>
        <div>
          <div>add a b = add' a b</div>
          <div>        where add' [] [] = []</div>
          <div>              add' (a:as) (b:bs) = (add' as bs) ++ [a+b]
            -- reversed output</div>
        </div>
        <div><br>
        </div>
        <div>
          Obviously, the same function can be written as:</div>
        <div>zipWith (+) [1,2,3] [1,2,3]</div>
        <div><br>
        </div>
        <div>hth,</div>
        <div>L.</div>
      </div>
    </blockquote>
    <br>
  </body>
</html>