哈斯克尔函数折叠器 [英] Haskell foldr with function

查看:118
本文介绍了哈斯克尔函数折叠器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  kxy = x 
$

我想了解下面的代码是如何评估Haskell foldr的。 b $ b foldr k 1 [0..5]

结果为0,但我可以'不明白为什么它是零?我想认为x是1,列表中的任何元素都是y。任何人都可以向我解释一下吗?我在网上搜索了它,但找不到任何有用的东西。

Haskell Wiki 有关于如何解释 foldr 的一些有用信息,包括这张图片:




$ b $你可以看到你的表达式是如何展开的:

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


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

这篇关于哈斯克尔函数折叠器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆