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
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
| Original language | English |
|---|---|
| Article number | 198 |
| Pages (from-to) | 275–304 |
| Number of pages | 30 |
| Journal | Proceedings of the ACM on Programming Languages |
| Volume | 7 |
| Issue number | ICFP |
| DOIs | |
| Publication status | Published - 30 Aug 2023 |
Bibliographical note
Publisher Copyright:© 2023 Owner/Author.
Keywords
- FBIP
- Tail Recursion Modulo Cons
Fingerprint
Dive into the research topics of 'FP2: Fully in-Place Functional Programming'. Together they form a unique fingerprint.Cite this
- APA
- Author
- BIBTEX
- Harvard
- Standard
- RIS
- Vancouver