Affiliation:
1. University of Edinburgh, UK
2. Microsoft Research, USA
3. Utrecht University, Netherlands
Abstract
As functional programmers we always face a dilemma: should we write purely
functional code, or sacrifice purity for efficiency and resort to in-place
updates? This paper identifies precisely when we can have the best of both
worlds: a wide class of purely functional programs can be executed safely using
in-place updates without requiring allocation, provided their arguments are not
shared elsewhere.
We describe a linear _fully in-place_ (FIP) calculus where we prove that we can
always execute such functions in a way that requires no (de)allocation and uses
constant stack space. Of course, such a calculus is only relevant if we can
express interesting algorithms; we provide numerous examples of in-place
functions on datastructures such as splay trees or finger trees, together with
in-place versions of merge sort and quick sort.
We also show how we can generically derive a map function over _any_ polynomial
data type that is fully in-place. Finally, we have implemented the rules of the
FIP calculus in the Koka language. Using the Perceus reference counting garbage
collection, this implementation dynamically executes FIP functions in-place
whenever possible.
Publisher
Association for Computing Machinery (ACM)
Subject
Safety, Risk, Reliability and Quality,Software
Cited by
4 articles.
订阅此论文施引文献
订阅此论文施引文献,注册后可以免费订阅5篇论文的施引文献,订阅后可以查看论文全部施引文献
1. Oxidizing OCaml with Modal Memory Management;Proceedings of the ACM on Programming Languages;2024-08-15
2. The Functional Essence of Imperative Binary Search Trees;Proceedings of the ACM on Programming Languages;2024-06-20
3. Functional Ownership through Fractional Uniqueness;Proceedings of the ACM on Programming Languages;2024-04-29
4. FP²: Fully in-Place Functional Programming;Proceedings of the ACM on Programming Languages;2023-08-30