如何在Haskell中编写foldr HOF

发布于 2024-08-26 02:21:32 字数 68 浏览 1 评论 0原文

我想在我的元组中添加一些金额。我想把它拿出来并汇总并展示。 我想使用Foldr功能。

有人可以帮我怎么做吗

i want to add some amounts which in my tuple. i want to take that out and total it and show.
i want to use Foldr function.

can someone help me out how to do

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哎呦我呸! 2024-09-02 02:21:32

假设您有一个元组列表,您可能想从阅读折叠函数开始,也许这里。它深入到foldl,但foldr 是相似的。它只是从列表的另一端开始工作。 这个其他线程底部的图形表示应该有所帮助。

完成此操作后,您应该能够弄清楚细节。我假设您已经知道如何从元组中获取值?

Assuming you have a list of tuples, you probably want to start by reading up on the fold functions, perhaps here. It dives into foldl, but foldr is similar. It just works from the other end of the list. The graphical representation at the bottom of this other thread should help.

Once you've done that, you should be able to work out the details. I assume you already know how to get a value out of a tuple?

失与倦" 2024-09-02 02:21:32

你不能。 foldr (和 foldl 等)适用于列表,而不是元组。

You can't. foldr (and foldl, etc) work on lists, not tuples.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文