Purely functional data structure: Difference between revisions

Content deleted Content added
A slightly less arbitrary example (length can be obtained from the returned new list without further mutation).
Line 20:
requires adding these data structures as explicit outputs.
 
For instance, consider a function that accepts a mutable list, insertsremoves anthe first element intofrom the list, and returns thethat length of the new listelement. In a purely functional setting, insertingremoving a newan element intofrom the list produces a new and shorter list, but does not update the original one. In order to be useful, therefore, a purely functional version of this function is likely to have to return both the lengthnew oflist thealong list andwith the newremoved list itselfelement. In the most general case, a program converted in this way must return the "state" or "store" of the program as an additional result from every function call. Such a program is said to be written in [[store-passing style]].
 
==Examples==