Abstract
We describe an efficient representation of purely functional arrays suggested by Holmström and Hughes, here calledversion tree arrays orv-arrays. A collection of arrays is represented by aversion tree where the root array is stored in contiguous memory as usual and every other array is represented as a node that records the difference to its father. Updating is done by adding a new node to the version tree and takes constant time, while the time for subscripting is proportional to the distance to the root. Essential for efficiency is therefore the possibility to reroot the tree without changing the semantics of the subscript operation, i.e. the values that the arrays represent.
We also show howv-arrays can be implemented in Standard ML and compare the efficiency ofv-arrays to other representations, like binary trees, lists and functions, by measuring the execution time of some programs that use sequences.v-arrays turn out to be superior in practice in algorithms that use arrays singlethreadedly and access them randomly.
Similar content being viewed by others
References
H. G. Baker,Shallow binding in Lisp 1.5. Comm. ACM 21 :7.
S. Holmström,How to handle large data structures in functional languages, inProc. of the SERC/Chalmers workshop on Declarative Programming Languages, University College London (1983).
L.-H. Eriksson and M. Rayner,Incorporating mutable arrays into logic programming, inProc. of the 2nd int. Logic Programming Conference, Uppsala (1984).
P. Hudak,A semantic model of reference counting and its abstraction, inProc. of the ACM Symposium on LISP and Functional Programming, Cambridge, Mass., (1986).
P. Hudak and A. Bloss,The aggregate update problem in functional programming systems, in 12th ACM Symp. on Principles of Programming Languages, New Orleans (1985).
J. Hughes,An efficient implementation of purely functional arrays, Dept. of Computer Sciences, Chalmers University of Technology, Göteborg (1985).
R. Milner,The Standard ML Core Language, University of Edinburgh (1985).
A. Mycroft,Abstract Interpretation and Optimizing Transformations for Applicative Programs, Doctoral dissertation, University of Edinburgh (1981).
D. Schmidt,Detecting global variables in denotational specifications, TOPLAS vol. 7, pp. 299–310, (1985).
J. Schwarz,Verifying the safe use of destructive operations in applicative programs, in 3eme Colloque Internat. sur la Programmation, Dunod, Paris (1978).
W. F. Tichy,Design, implementation and evaluation of a revision control system, inProc. of the 6th Int. Conf. on Software Engineering, IEEE, Tokyo, Sept. 1982.
Author information
Authors and Affiliations
Additional information
This work has been supported by STU, the Swedish Board for Technical Development.