Are some data structures more suitable for functional programming than others?

后端 未结 9 679
灰色年华
灰色年华 2021-01-31 19:23

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, w

9条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 19:29

    • Yes. Typically tuples, lists, and partially-evaluated functions are very common data structures in functional programming languages. Mutable data structures, like arrays and (real) hash tables, are used much less because they don't fit in as well with Haskell. SML (which is also functional, but not lazy) can use arrays more naturally than Haskell, but lists are still more common because they map well to recursive algorithms.
    • I'm not sure how to answer this. A problem for who?
    • There exist implementations of associative arrays ("hash table" equivalent) which can continue to share most of their underlying structure even after different updates. I believe GHC's Data.Map does; also, Edison has quite a few lazy/functional-friendly data structures.

提交回复
热议问题