In pure functional programming, all data structures are immutable, meaning that they cannot be changed once created. Lauren asked me what I wanted for cover art.
Influence First of all, I think that we can categorize "influence" as one of either: So long as the contents of the tail are immutable, this sharing will be invisible to the program.
In order to avoid an inefficient operation where the Okasaki thesis list is reversed, real-time queues Okasaki thesis the restriction that the rear list is only as long as the front list. You can sort of do this Okasaki thesis Haskell, but not cleanly.
As a result, the original lists xs and ys persist and have not been modified. In order to ensure that a data structure is used in a purely functional way in an impure functional language, modules or classes can be used to ensure manipulation via authorized functions only. Reactions Initial reviews were positive and the hardcover edition sold out pretty quickly, so Cambridge University Press released a paperback edition the following year.
The vectors are similar to what you find in Clojure. Because the trees are immutable, when you want to delete something, you can simply revert back to a previous version of the tree from before the unwanted item was inserted. Linked lists[ edit ] This example is taken from Okasaki. In both cases, people can use the described data structures or a similar one, without actually having read his book directly.
Trees[ edit ] This example is taken from Okasaki. Modification time and space are bounded by Okasaki thesis size of the structure, since a single modification may cause the entire structure to be copied. The only computation required is for the first kind of data that will actually be performed.
The idea was to choose or create a number system with the properties you want such as constant-time additionand then build the data structure on top of that.
However, some common data structures, such as FIFO queues and arrays, can actually be quite difficult to implement this way.
This is an amortized time bound, assuming we store the modification history in a growable array. Some other languages, such as OCamlallow the explicit definition of recursive values.
Some people take this as a sign that functional languages are impractical.
Therefore, lazy evaluation naturally becomes an important part of the construction of purely functional data structures. Laziness and memoization[ edit ] Lazy evaluation is particularly interesting in a purely functional language because the order of the evaluation never changes the result of a function.
Whenever we access a node, we check the modification box, and compare its timestamp against the access time. Again, this was a case where the implementation was simple, but the analysis was a bear. Therefore, the code of a purely functional data structure can, without loss of efficiency, consider similar data that will effectively be used and data that will be ignored.
A modification takes O 1 amortized space, and O 1 amortized time. Although tries are briefly described by Okasaki, they were known before, and this data structure is quite far from anything else described in there. This is almost always both the easiest and the right thing to do. Examples of persistent data structures[ edit ] Perhaps the simplest persistent data structure is the singly linked list or cons-based list, a simple list of objects formed by each carrying a reference to the next in the list.
Their result was quite nice, but rather complicated, so I started looking for a simpler approach. I thought that the basic organization of my dissertation was pretty solid, so mostly I was able to focus on adding and adjusting things to make it work better as a book. Rather than a branching tree, combinations of versions induce a DAG directed acyclic graph structure on the version graph.
Secondly many common nodes are shared between the old tree and the new tree. Here is a list of abstract data structures with purely functional implementations: That changed one day during a walk in the snow.
The reason for the copy is that the last node in xs the node containing the original value 2 cannot be modified to point to the start of ys, because that would change the value of xs. I considered a bunch of topics related to functional programming, but none of them seemed right. Each extra field value has an associated field name and a version stamp which indicates the version in which the named field was changed to have the specified value.
However, if the language is not purely functional, the run-time system may be unable to guarantee immutability.In computing, a persistent data structure is a data structure that always preserves the previous version of itself when it is modified.
Such data structures are effectively immutable, as their operations do not (visibly) update the structure in-place, but instead always yield a new updated structure. This is Okasaki's thesis.
The book is an expanded and revised version of the thesis. The process of turning my dissertation into a book was pure joy. In computer science, a purely functional data structure is a data structure that can be implemented in a purely functional language.
The main difference between an arbitrary data structure and a purely functional one is that the latter is (strongly) immutable. Okasaki's book of the same name, based on his thesis, is one of my favourites—I'd recommend it to all programmers, not just those doing a lot of functional programming.
The explanations are lucid and insightful, and the. SlowingtheEvolutionandOutbreakof AntibioticResistance Colin Okasaki JonJacobsen,Advisor JulieBlackwood,Reader DepartmentofMathematics May, Purely Functional Data Structures Chris Okasaki September CMU-CS School of Computer Science Carnegie Mellon University Pittsburgh, PA This thesis addresses this imbalance by speciﬁcally considering the design and analysis of functional data structures.Download