一些数据结构比其他数据结构更适合于功能编程吗? [英] Are some data structures more suitable for functional programming than others?

查看:95
本文介绍了一些数据结构比其他数据结构更适合于功能编程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Real World Haskell 中,有一节题为Life without arrays or hash table的作者建议在函数式编程中首选列表和树,而在命令性程序中可能会使用数组或散列表。

In Real World Haskell, there is a section titled "Life without arrays or hash tables" where the authors suggest that list and trees are preferred in functional programming, whereas an array or a hash table might be used instead in an imperative program.

这是很有道理的,因为它更容易在创建新的列表或树之前,要重新使用一部分(不可变)列表或树,而不是使用数组。

This makes sense, since it's much easier to reuse part of an (immutable) list or tree when creating a new one than to do so with an array.

所以我的问题是:


  • 功能和命令式编程之间的数据结构的使用模式是否真的有明显的不同?

  • 如果是,这是一个问题?

  • 如果您真的需要一些应用程序的哈希表,该怎么办?你简单地吞下额外的修改费用?

推荐答案

这本书纯功能数据结构深入介绍了您的问题,并且包括主要在ML中的理论和实现的大量组合 - 该附录还包含Haskell实现,因此您应该能够跟随一点额外的页面转动。这是一个很好的(尽管部分困难)阅读,如果你真的有兴趣对你的问题的彻底的答案。说,我认为ephemient给了一个很好的简短的答案。

The book Purely Functional Data Structures covers your questions in depth, and includes a great mix of theory and implementations primarily in ML - the appendix also contains Haskell implementations so you should be able to follow along with a bit of extra page turning. It is a pretty good (though difficult in parts) read if you are really interested in a thorough answer to your questions. Having said that I think ephemient gave a superb short answer.

编辑:Steven Huwig提供了一个链接本书开始的论文。虽然我没有阅读它,但唯一缺少的东西(从目录中判断)是Haskell的实现。

edit: Steven Huwig provided a link to the thesis that the book started as. While I haven't read through it the only big thing missing (judging from the table of contents) are the Haskell implementations.

这篇关于一些数据结构比其他数据结构更适合于功能编程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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