<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>foldr doesn't begin anywhere.</p>
    <p><a class="moz-txt-link-freetext" href="https://vimeo.com/64673035">https://vimeo.com/64673035</a><br>
    </p>
    <br>
    <div class="moz-cite-prefix">On 29/12/16 06:43, Imants Cekusins
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAP1qina8g7XF9nnipFvu4dEzVX9fv_vS2=76JaDF-DkAgmrfdw@mail.gmail.com"
      type="cite">
      <div dir="ltr"><span style="font-size:14px">> you would want to
          use foldr, not foldl</span>
        <div><br>
          <div class="gmail_extra">foldl vs foldr baffles me a bit.</div>
        </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">in Erlang <a moz-do-not-send="true"
            href="http://erlang.org/doc/man/lists.html#foldl-3">http://erlang.org/doc/man/lists.html#foldl-3</a></div>
        <div class="gmail_extra">use of <b>foldl</b> is suggested. I
          got used to this and usually use foldl. </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">another reason is: it appears that in
          Haskell - same as Erlang - <b>foldl</b> enumerates items in
          "natural" order: in [1,2] 1 is passed to the fn, then 2</div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra"><b>foldr</b> on the other hand begins
          with 2 and ends with 1.</div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">however: <b>foldr</b> arg order: a
          -> acc  is more natural.</div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">I very rarely deal with large lists and
          never (so far) with inifinites.</div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">for this case for which I consider and
          use Alternatives - the list would be 2 - 5 items long. The
          order though is important. </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">>>> asum [Just 1, Just 2]  </div>
        <div class="gmail_extra">Just 1</div>
        <div class="gmail_extra">
          <div class="gmail_extra">>>> asum [Nothing, Just 1,
            Nothing, Just 2, Nothing]</div>
          <div class="gmail_extra">Just 1<br>
          </div>
          <div class="gmail_extra"><br>
          </div>
          <div class="gmail_extra">looks "naturally" ordered: tested
            left to right. </div>
          <div class="gmail_extra"><br>
          </div>
          <div class="gmail_extra">I may not understand the workings
            (memory and such) of foldl vs foldr however I hope that for
            small lists it is sufficient to focus on the order of
            element processing.</div>
          <div class="gmail_extra"><br>
          </div>
          <div class="gmail_extra">order matters. This example hopefully
            confirms that foldr begins @ end, foldl begins @ start. Same
            as in Erlang ;)</div>
          <div class="gmail_extra"><br>
          </div>
          <div class="gmail_extra">
            <div class="gmail_extra">Prelude Data.Foldable> <b>foldr</b>
              (\i1 acc1 -> i1 + acc1 * 2) 0 [1,2]</div>
            <div class="gmail_extra">5</div>
            <div class="gmail_extra">Prelude Data.Foldable> <b>foldl</b>
              (\acc1 i1 -> i1 + acc1 * 2) 0 [1,2]</div>
            <div class="gmail_extra">4</div>
            <div><br>
            </div>
          </div>
          <div><br>
          </div>
        </div>
        <div class="gmail_extra">
          <div><br>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@haskell.org">Beginners@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>