简体   繁体   English

Haskell foldr具有功能

[英]Haskell foldr with function

I would like to understand how the below code of Haskell foldr is evaluated. 我想了解如何评估下面的Haskell foldr代码。

k x y = x

foldr k 1 [0..5]

The result is 0, but I can't understand why it is zero? 结果是0,但我不明白为什么它是零? I would like to think that x is 1 any the elements in the list are y. 我想x是1,列表中的任何元素都是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: Haskell Wiki有一些关于如何解释foldr有用信息,包括这个图像:

在此输入图像描述

You can see how your expression expands to: 您可以看到表达式如何扩展为:

0 `k` (1 `k` ... (5 `k` 1)))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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