<div style='font-family:Arial; font-size:13px;'><br><br><div>May 27, 2020 11:33:58 PM CEST Tony Morris <tonymorris@gmail.com> wrote:<blockquote type="cite" cite="<d75add66-7101-e6a6-00cf-89a0c3cb3959@gmail.com>"><pre style="font-size:13px;">foldl does a loop, foldr does constructor replacement<br><br><a href="https://www.youtube.com/watch?v=GPwtT31zKRY" target="_blank">https://www.youtube.com/watch?v=GPwtT31zKRY</a><br><br>On 5/28/20 4:55 AM, Alexander Chen wrote:<br>> Hi,<br>> <br>> I guess it's time to get acquainted with foldr and foldl.<br>> <br>> *prelude>xs = [1..5] ++ undefined*<br>> *prelude> foldr const 0 xs*<br>> <b>1</b><br>> <br>> I assume it goes something like this:<br>> <br>> ( 1 `const`(2 `const`(3 `const`(4 `const`(5 `const`(undefined `const`<br>> 0))))))<br>>                                                               (<br>> 5 `const` undefined)<br>>                                                (4 `const` 5)    <br>>                                 (3 `const` 4)<br>>                 ( 2 `const` 3)<br>> (1 `const`2)<br>> = 1<br>> <br>> ========================================================================<br>> <br>> <br>> What i don't get is the opposite:<br>> <br>> *prelude> foldl const 0 xs*<br>> <b>error</b><br>> <br>> <br>> in my mind this should go like this: <br>> ((((((0`const`1)`const` 2) `const` 3 )`const` 4)`const`  5)<br>> `const` undefined)<br>>                     (0 `const`2)<br>>                                       (0`const` 3)            <br>>                                                       ( 0`const`4)<br>>                                                                      <br>>  (0`const` 5)<br>>                                                                        <br>>               (0 `const` undefined )<br>> = 0<br>> <br>> <br>> <br>> I have been told that the main difference between foldl and foldr is<br>> that foldl needs to evaluate the whole spline before it continues. And i<br>> guess that has something to do with it. What I don't understand is WHY<br>> foldl need to do this and foldr doesn't.<br>> <br>> <br>> thanks in advance!<br>> <br>> best,<br>> <br>> _______________________________________________<br>> Beginners mailing list<br>> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>> <br><br><br>_______________________________________________<br>Beginners mailing list<br>Beginners@haskell.org<br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br></pre></blockquote></div><br><br><div><div style="font-family:Arial; font-size:13px;"><br></div></div></div>