I would like to understand how the below code of Haskell foldr is evaluated.
k x y = x
foldr k 1 [0..5]
The result is 0, but I can't understand why it is zero? I would like to think that x is 1 any the elements in the list are y. Can anyone explain it to me, please? I searched it online but couldn't found anything useful.
The Haskell Wiki has some useful info about how to interpret foldr, including this image:

You can see how your expression expands to:
0 `k` (1 `k` ... (5 `k` 1)))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With