Implementing Functional Programs Using Mutable Abstract Data Types

Suppose we have a purely functional [lo] program P that uses a set of abstract data types [9,3] by invoking their operations. Suppose we view every abstract data type in P to be mutable, i.e., one in which some of the operations creates an instance of the module type by destructively updating the old instance, rather than creating a new copy. This will, in general, alter the meaning of P. P with mutable data types is sensitive to the order of evaluation of the data type operations in it. This poses the following interesting questions: Is there a way of correctly implementing a functional program employing in situ (in place) update operations so that no copying is necessary? If so, under what conditions is this possible? In this paper, we study a property, referred to as the in situ evaluability property of functional programs, which helps answer the above questions. be found such that the intended semantics o\f P is preserved. This evaluation order will be called the in situ evaluation order. Our work analyses the conditions for in situ evaluation in the context of applicative order evaluation. We formulate syntactic conditions on functional programs, and show that they are sufficient to ensure in situ evaluation. These conditions are also necessary for expressions not containing conditionals or recursion. (For conditionals and recursive expressions, a set of necessary syntactic conditions seems to be impossible to formulate because of the undecidability of the halting problem.) The proof that our syntactic conditions are sufficient is constr!tctive in that it defines the in situ evaluation order.

[1]  David Robson,et al.  Smalltalk-80: The Language and Its Implementation , 1983 .

[2]  Pierre Lescanne,et al.  Computer experiments with the REVE term rewriting system generator , 1983, POPL '83.

[3]  Paul Hudak,et al.  The aggregate update problem in functional programming systems , 1985, POPL.

[4]  Ellis Horowitz,et al.  Abstract data types and software validation , 1978, CACM.

[5]  Alfred V. Aho,et al.  Compilers: Principles, Techniques, and Tools , 1986, Addison-Wesley series in computer science / World student series edition.

[6]  Edsger W. Dijkstra,et al.  A Discipline of Programming , 1976 .

[7]  Peter Henderson Functional Programming , 1980 .

[8]  Alfred Laut Safe Procedural Implementations of Algebraic Types , 1980, Inf. Process. Lett..

[9]  Craig Schaffert,et al.  CLU Reference Manual , 1984, Lecture Notes in Computer Science.