## Breaking the Complexity Barrier of Pure Functional Programs with Impure Data Structures

### BibTeX

@MISC{Wuille_breakingthe,

author = {Pieter Wuille and Tom Schrijvers},

title = {Breaking the Complexity Barrier of Pure Functional Programs with Impure Data Structures},

year = {}

}

### OpenURL

### Abstract

Abstract. Pure functional programming language offer many advantages over impure languages. Unfortunately, the absence of destructive update, imposes a complexity barrier. In imperative languages, there are algorithms and data structures with better complexity. We present our project for combining existing program transformation techniques to transform inefficient pure data structures into impure ones with better complexity. As a consequence, the programmer is not exposed to the impurity and retains the advantages of purity. 1

### Citations

254 |
Efficiency of a good but not linear set union algorithm
- Tarjan
(Show Context)
Citation Context ...ir representatives. – union: merge two sets (given by an element that is contained in them) into one. By doing this, all elements of both sets will get the same representative. The algorithm given in =-=[13]-=- models the items in the set as nodes in a forest, where each node refers to one other node to which it is equal. By adding the optimizations path compression (where each node is made to point to the ... |

124 |
98 Language and Libraries: The Revised Report
- Haskell
- 2003
(Show Context)
Citation Context ...reliminaries We introduce a simple first-order functional language to demonstrate code examples. Our target language is an impure extension of the pure source language. The syntax is based on Haskell =-=[8]-=-, but the operational semantics is strict in order to accommodate the target language’s impurity. 2.1 The Pure Source Language A program consists of a number of first-order function definitions and da... |

90 | Beyond induction variables
- Wolfe
- 1992
(Show Context)
Citation Context ...1) else seek_L (n-1) lb (ls-1) Strength Reduction After realizing the recursive call decreases the first and second arguments equally, until the second one is zero, we can use strength reduction (eg. =-=[15]-=-) to reach: seek n l = case l of L lb ls -> seek_L n lb ls seek_L n lb ls = if n >= ls then error "index out of bounds" else get (array lb) (ls-1-n) Inlining Again After inlining the now non-recursive... |

82 | A transformation-based optimiser for Haskell
- Jones, Santos
- 1998
(Show Context)
Citation Context ...= size l - 1}) Field Selector Inlining and Outward Floating of Case Expressions As many field selectors are used on the same variable l, we inline them as case expressions and float them outward (see =-=[7]-=-) so they can be shared: seek n l = case l of L lb ls -> if ls == 0 then error "index out of bounds" else if n == 0 then get (array lb) (ls-1) else seek (n-1) (L {back = lb, size = ls - 1})Constructo... |

62 | Cheap Deforestation for Non-strict Functional Languages
- Gill
- 1996
(Show Context)
Citation Context ...eveloped, e.g. those in the Edison library [10], do not overcome the complexity barrier. Also, of the many works conducted on program transformation and optimization, the majority, e.g. deforestation =-=[4]-=-, focusses on the improvement of constant factors, and not complexity. Only a small minority can improve complexity, e.g. the worker-wrapper transformation [5] or tupling [2], but are still limited by... |

41 |
An analysis of inline substitution for a structured programming language
- Scheifler
- 1977
(Show Context)
Citation Context ... isnil l then error "index out of bounds" else if n == 0 then head l else seek (n-1) (tail l) Implementation Inlining Once the implementation of the abstract interface is chosen, it can be be inlined =-=[11]-=- (unfolded) at the use sites. This removes the overhead of the abstraction layer introduced earlier, and generating code that again directly operates on the data structure representation. If we had ch... |

32 | Shallow Binding in Lisp 1.5
- Baker
- 1978
(Show Context)
Citation Context ...eferable over ALists’ O(1) look-up time (if Arrays or VLists are used) but O(n) modification time. Even better performance can be obtained by using an observably persistent data structure proposed in =-=[6]-=-, as shown in [3], which does use destructive update. The key idea is representing the latest version used of the persistent array as a real Array, and other versions as a tree of modifications each p... |

16 | S.: Call-pattern specialisation for Haskell programs
- Jones
- 2007
(Show Context)
Citation Context ...out of bounds" else if n == 0 then get (array lb) (ls-1) else seek (n-1) (L {back = lb, size = ls - 1})Constructor Specialization If we specialize the seek function with respect to the list argument =-=[9]-=-, we get a helper function with two separate arguments (ls and lb): seek n l = case l of L lb ls -> seek_L n lb ls seek_L n lb ls = if ls == 0 then error "index out of bounds" else if n == 0 then get ... |

15 | An Overview of Edison
- Okasaki
- 2001
(Show Context)
Citation Context ...icient purely functional data structures, and program transformations for program optimization. However, the many efficient pure functional data structures developed, e.g. those in the Edison library =-=[10]-=-, do not overcome the complexity barrier. Also, of the many works conducted on program transformation and optimization, the majority, e.g. deforestation [4], focusses on the improvement of constant fa... |

7 | Fast functional lists, hash-lists, deques and variable length arrays
- Bagwell
- 2002
(Show Context)
Citation Context ...size l)==0 The VList implementation for ALists When no copy operations are required for cons, Arrays are the best we can achieve. Otherwise, a more involved data structure is more appropriate, VLists =-=[1]-=-, for which cons always takes O(1) time. The idea of the VList is to present an AList as a linked list of blocks of exponentially increasing size. Each block consists of an Array (of pre-determined si... |

5 | A Persistent Union-Find Data Structure
- Conchon, Filliâtre
- 2007
(Show Context)
Citation Context ... rank (the shallowest tree is made to point to the tallest one), it attains an amortized time complexity of O(nα −1 (n)), i.e. nearlinear time. 2 A variant of union-find, called persistent union-find =-=[3]-=-, can be implemented in a purely functional way. Instead of storing the points-to relation inside the nodes, the nodes only contain an index into a shared persistent array that contains the indices of... |

2 | N.: Redundant Call Elimination via Tupling
- Chin, Khoo, et al.
- 2005
(Show Context)
Citation Context ...ority, e.g. deforestation [4], focusses on the improvement of constant factors, and not complexity. Only a small minority can improve complexity, e.g. the worker-wrapper transformation [5] or tupling =-=[2]-=-, but are still limited by the complexity barrier. The reason is that these transformations all restrict themselves to pure target languages.7 Conclusions In this paper we have described a systematic... |

2 |
The Worker Wrapper Transformation
- Gill, Hutton
(Show Context)
Citation Context ...zation, the majority, e.g. deforestation [4], focusses on the improvement of constant factors, and not complexity. Only a small minority can improve complexity, e.g. the worker-wrapper transformation =-=[5]-=- or tupling [2], but are still limited by the complexity barrier. The reason is that these transformations all restrict themselves to pure target languages.7 Conclusions In this paper we have describ... |

2 |
Practical OCaml. APress
- Smith
- 2005
(Show Context)
Citation Context ...ted in a purely functional way, on Lists, or imperatively on destructably overwritable Arrays. Although constant factors differ, their complexity does not. We consider the implementation in the Ocaml =-=[12]-=- standard library; it is a pure version of mergesort that acts as a stable list sorting algorithm. Step 1: Abstraction Since this algorithm is implemented directly on Lists, it was abstracted to only ... |

1 |
Provably perfect shuffle algorithms, 2001. http://okmij.org/ ftp/Haskell/perfect-shuffle.txt [Online; accessed 7-August-2008
- com
(Show Context)
Citation Context ... shuffling algorithm would end up having O(n 2 ) time complexity. An alternative is using complete binary trees, with all nodes having a field listing the amount of subnodes they contain, as shown in =-=[14]-=-. Since in eachoperation the path to the root needs to be duplicated, this results in a pure O(n log n) shuffling algorithm. If we drop the pureness restriction however, and reuse the persistent arra... |