简体   繁体   中英

Haskell foldr with function

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)))))

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM