Stretching the Storage Manager: Weak Pointers and Stable Names in Haskell Simon Peyton Jones1,SimonMarlow2, and Conal Elliott3 1 Microsoft Research, Cambridge,
[email protected] 2 Microsoft Research, Cambridge,
[email protected] 3 Microsoft Research, Redmond,
[email protected] Abstract. Every now and then, a user of the Glasgow Haskell Com- piler asks for a feature that requires specialised support from the storage manager. Memo functions, pointer equality, external pointers, finalizers, and weak pointers, are all examples. We take memo functions as our exemplar because they turn out to be the trickiest to support. We present no fewer than four distinct mech- anisms that are needed to support memo tables, and that (in various combinations) satisfy a variety of other needs. The resulting set of primitives is undoubtedly powerful and useful. Whether they are too powerful is not yet clear. While the focus of our discussion is on Haskell, there is nothing Haskell-specific about most of the primitives, which could readily be used in other settings. 1 Introduction \Given an arbitrary function f, construct a memoised version of f; that is, construct a new function with the property that it returns exactly the same results as f, but if it is applied a second time to a particular argument it returns the result it computed the first time, rather than recomputing it." Surely this task should be simple in a functional language! After all, there are no side effects to muddy the waters. However, it is well known that this simple problem raises a whole raft of tricky questions.