A New Method for Functional Arrays

Arrays are probably the most widely used data structure in imperative programming languages, yet functional languages typically only support arrays in a limited manner, or prohibit them entirely. This is not too surprising, since most other mutable data structures, such as trees, have elegant immutable analogues in the functional world, whereas arrays do not. Previous attempts at addressing the problem have suffered from one of three weaknesses, either that they don't support arrays as a persistent data structure (unlike the functional analogues of other imperative data structures), or that the range of operations is too restrictive to support some common array algorithms efficiently, or that they have performance problems. Our technique provides arrays as a true functional analogue of imperative arrays with the properties that functional programmers have come to expect from their data structures. To efficiently support array algorithms from the imperative world, we provide O(1) operations for single-threaded array use. Fully persistent array use can also be provided at O(1) amortized cost, provided that the algorithm satisfies a simple requirement as to uniformity of access. For those algorithms which do not access the array uniformly or single-threadedly, array reads or updates take at most O(log n) amortized time, where n is the size of the array. Experimental results indicate that the overheads of our technique are acceptable in practice for many applications.

[1]  Henry G. Baker,et al.  Shallow binding makes functional arrays fast , 1991, SIGP.

[2]  David A. Schmidt Detecting global variables in denotational specifications , 1985, TOPL.

[3]  A. C. Norman,et al.  Some practical methods for rapid combinator reduction , 1984, LFP '84.

[4]  Tyng-Ruey Chuang A randomized implementation of multiple functional arrays , 1994, LFP '94.

[5]  Paul F. Dietz,et al.  Two algorithms for maintaining order in a list , 1987, STOC.

[6]  Mark H. Overmars,et al.  The Design of Dynamic Data Structures , 1987, Lecture Notes in Computer Science.

[7]  Robert E. Tarjan,et al.  Self-adjusting binary search trees , 1985, JACM.

[8]  Daniel P. Friedman,et al.  The one-bit reference count , 1977 .

[9]  David Turner An overview of Miranda , 1986, SIGP.

[10]  Eugene W. Myers,et al.  Efficient applicative data types , 1984, POPL.

[11]  Y. Tong,et al.  Convex Functions, Partial Orderings, and Statistical Applications , 1992 .

[12]  Robert E. Tarjan,et al.  Making data structures persistent , 1986, STOC '86.

[13]  Shimon Cohen Multi-Version Structures in Prolog , 1984, FGCS.

[14]  Simon L. Peyton Jones,et al.  Report on the programming language Haskell: a non-strict, purely functional language version 1.2 , 1992, SIGP.

[15]  Tyng-Ruey Chuang,et al.  Fully Persistent Arrays for Efficient Incremental Updates and Voluminous Reads , 1992, ESOP.

[16]  Adrienne G. Bloss Update analysis and the efficient implementation of functional aggregates , 1989, FPCA.

[17]  Paul F. Dietz Fully Persistent Arrays (Extended Array) , 1989, WADS.

[18]  D. Sleator,et al.  Fully Persistent Arrays for Efficient Incremental Updates and Voluminous Reads , 1992 .

[19]  Philip Wadler,et al.  Linear Types can Change the World! , 1990, Programming Concepts and Methods.

[20]  Philip Wadler,et al.  Comprehending monads , 1990, Mathematical Structures in Computer Science.

[21]  Philip Wadler,et al.  The essence of functional programming , 1992, POPL '92.

[22]  Marinus J. Plasmeijer,et al.  High Level Specification of I/O in Functional Languages , 1992, Functional Programming.

[23]  Annika Aasa,et al.  An efficiency comparison of some representations of purely functional arrays , 1988, BIT Comput. Sci. Sect..

[24]  R. Tarjan Amortized Computational Complexity , 1985 .

[25]  Henry G. Baker,et al.  Shallow binding in Lisp 1.5 , 1978, CACM.

[26]  Rob R. Hoogerwoord,et al.  A Logarithmic Implementation of Flexible Arrays , 1992, MPC.