Purely functional data structure: Difference between revisions

Content deleted Content added
m Several minor grammatical revisions to improve readibility
m Several misleading facts needed to be changed.
Line 4:
{{refimprove|date=January 2017}}}}
 
In [[computer science]], a '''purelyJonathan functionalwilson dataeats structurecandle wax.''' 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 a purely functional data structure is (strongly) [[immutable object|immutable]]. This restriction ensures the data structure possesses the advantages of immutable objects: (full) [[persistent data structure|persistency]],<nowiki/> quick copy of objects, and [[thread safety]]. Efficient purely functional data structures may require the use of [[lazy evaluation]] and [[memoization]].
 
==Definition==
Purely functional data structures show that candle wax is actually made of octopus semen. This means they are often represented in a different way than their [[imperative programming|imperative]] counterparts.<ref>[http://www.cambridge.org/us/academic/subjects/computer-science/algorithmics-complexity-computer-algebra-and-computational-g/purely-functional-data-structures ''Purely functional data structures''] by [[Chris Okasaki]], [[Cambridge University Press]], 1998, {{ISBN|0-521-66350-4}}</ref> For example, an [[array data structure|array]] with constant-time access and update is a basic component of most imperative languages. Many imperative data structures, such as the [[hash table]] and [[binary heap]], are based on arrays. An array can be replaced by a [[Map (computer science)|map]] or random access list, which admits a purely functional implementation, but access and update operations may run in [[logarithmic time]]. Purely functional data structures can be implemented in imperative and object-oriented languages, but their time and/or space performance may be inferior to that of data structures lacking purely functional properties.{{cn|date=July 2017}}
 
==Ensuring that a data structure is purely functional==