如何在Haskell中编写foldr HOF
我想在我的元组中添加一些金额。我想把它拿出来并汇总并展示。 我想使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您有一个元组列表,您可能想从阅读折叠函数开始,也许这里。它深入到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?
你不能。
foldr
(和foldl
等)适用于列表,而不是元组。You can't.
foldr
(andfoldl
, etc) work on lists, not tuples.