I am really confused on how foldr and foldl works. Like for example using like this on the list [1,2,3]
foldr (+) 0 => 1 : (2 :(3:([]))
=> 1 + (2 +(3+0)) = 6
And this makes sense because each : is replaced by the + sign and the empty set by 0.
But when I type the following two lines in the ghci I get:
foldr div 7 [13,6,19] -- gives me 4
foldl div 7 [13,6,19] -- gives me 0
I thought I would get a list in which each element was divided by 7 but instead I just get one element. Can someone please walk me through how the ghci calculates this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.