Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Foldl (Alexander Chen)
2. Re: Foldl (Tony Morris)
----------------------------------------------------------------------
Message: 1
Date: Wed, 27 May 2020 20:55:55 +0200 (CEST)
From: Alexander Chen <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Foldl
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi,
I guess it's time to get acquainted with foldr and foldl.
prelude>xs = [1..5] ++ undefined
prelude> foldr const 0 xs
1
I assume it goes something like this:
( 1 `const`(2 `const`(3 `const`(4 `const`(5 `const`(undefined `const` 0))))))
( 5 `const`
undefined)
(4 `const` 5)
(3 `const` 4)
( 2 `const` 3)
(1 `const`2)
= 1
========================================================================
What i don't get is the opposite:
prelude> foldl const 0 xs
error
in my mind this should go like this:
((((((0`const`1)`const` 2) `const` 3 )`const` 4)`const` 5) `const` undefined)
(0 `const`2)
(0`const` 3)
( 0`const`4)
(0`const` 5)
(0 `const` undefined )
= 0
I have been told that the main difference between foldl and foldr is that foldl
needs to evaluate the whole spline before it continues. And i guess that has
something to do with it. What I don't understand is WHY foldl need to do this
and foldr doesn't.
thanks in advance!
best,
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20200527/c4a1852e/attachment-0001.html>
------------------------------
Message: 2
Date: Thu, 28 May 2020 07:33:58 +1000
From: Tony Morris <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Foldl
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
foldl does a loop, foldr does constructor replacement
https://www.youtube.com/watch?v=GPwtT31zKRY
On 5/28/20 4:55 AM, Alexander Chen wrote:
> Hi,
>
> I guess it's time to get acquainted with foldr and foldl.
>
> *prelude>xs = [1..5] ++ undefined*
> *prelude> foldr const 0 xs*
> *1*
>
> I assume it goes something like this:
>
> ( 1 `const`(2 `const`(3 `const`(4 `const`(5 `const`(undefined `const`
> 0))))))
> (
> 5 `const` undefined)
> (4 `const` 5)
> (3 `const` 4)
> ( 2 `const` 3)
> (1 `const`2)
> = 1
>
> ========================================================================
>
>
> What i don't get is the opposite:
>
> *prelude> foldl const 0 xs*
> *error*
>
>
> in my mind this should go like this:
> ((((((0`const`1)`const` 2) `const` 3 )`const` 4)`const` 5)
> `const` undefined)
> (0 `const`2)
> (0`const` 3)
> ( 0`const`4)
>
> (0`const` 5)
>
> (0 `const` undefined )
> = 0
>
>
>
> I have been told that the main difference between foldl and foldr is
> that foldl needs to evaluate the whole spline before it continues. And i
> guess that has something to do with it. What I don't understand is WHY
> foldl need to do this and foldr doesn't.
>
>
> thanks in advance!
>
> best,
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20200528/a13e4316/attachment-0001.sig>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 143, Issue 16
******************************************