Complex data structures in Haskell - how do they work?

前端 未结 2 1021
礼貌的吻别
礼貌的吻别 2021-02-01 07:29

As I figured out, variables in Haskell are immutable (thus, they are not really `variables\').

In this case, if we have a complex and big data structure, like a red-bla

2条回答
  •  鱼传尺愫
    2021-02-01 07:51

    Yes, the solution is to return a new data structure which represents the modified value, however there is no requirement to copy the entire structure for your example (red-black trees) since you can just copy the nodes on the path from the root to the inserted node. This allows the insert operation to be the same complexity as the imperative version.

    Chris Okasaki's Purely functional data structures contains a number of implementations of immutable data structures - this book is a modified version of his phD thesis which you can find here

提交回复
热议问题