## Streaming Representation-Changers (2004)

### Cached

### Download Links

- [web.comlab.ox.ac.uk]
- [www.comlab.ox.ac.uk]
- [www.cs.ox.ac.uk]
- DBLP

### Other Repositories/Bibliography

Venue: | LNCS |

Citations: | 3 - 0 self |

### BibTeX

@ARTICLE{Gibbons04streamingrepresentation-changers,

author = {Jeremy Gibbons},

title = {Streaming Representation-Changers},

journal = {LNCS},

year = {2004},

volume = {3125},

pages = {142--168}

}

### OpenURL

### Abstract

Unfolds generate data structures, and folds consume them.

### Citations

5254 |
Design patterns: elements of reusable object-oriented software
- Gamma, Helm, et al.
- 1995
(Show Context)
Citation Context ...gami programming We are interested in capturing and studying recurring patterns of computation, such as folds and unfolds. As has been strongly argued by the recently popular design patterns movement =-=[8], id-=-entifying and exploring such patterns has many benefits: reuse of abstractions, rendering ‘folk knowledge’ in a more accessible format, providing a common vocabulary of discourse, and so on. What ... |

1307 | Lectures on constructive functional programming
- Bird
- 1989
(Show Context)
Citation Context ...for doing this: foldr fb= applyto b · foldr (·) id · map f where applyto b f �= fb. Because composition is associative with unit id, thefoldr on the right-hand side can — by the First Duality T=-=heorem [6] —-=- be replaced by a foldl. Although valid, this is not always very helpful. In particular, it can be quite inefficient — the fold now constructs a long composition of little functions of thesStreaming... |

663 |
Arithmetic coding for data compression
- Witten, Neal, et al.
- 1987
(Show Context)
Citation Context ...ream prod (⊙) ident lfts lfts �= �� k 0 � � 4k+2 2k+1 | k ← [1..] prod h �= if ⌊abs h 4⌋ n then Just (n, � 10 0 where n �= ⌊abs h 3⌋ 6.2 Arithmetic coding � −10n 1 ⊙ =-=h) else Nothing Arithmetic coding [40]-=- is a method for data compression. It can be more effective than rival schemes such as Huffman coding, while still being as efficient. Moreover, it is well suited to adaptive encoding, in which the co... |

400 | Deforestation: Transforming programs to eliminate trees
- Wadler
- 1990
(Show Context)
Citation Context ... fold; the structure of that data determines the structure of both its producer and its consumer. Under certain rather weak conditions, the intermediate data structure may be eliminated or deforested =-=[39]-=-, and the two phases fused into one slightly more efficient one. In this paper, we consider the opposite composition, of an unfold after a fold. Programs of this form consume an input data structure u... |

299 | Definitional interpreters for higher-order programming languages
- Reynolds
- 1972
(Show Context)
Citation Context ...ed until it is eventually applied to b. However, it is often possible that we can find some representation of those little functions that admits composition and application in constant time. Reynolds =-=[34] calls th-=-is transformation defunctionalization. Theorem 3. Given fold arguments f :: α → β → β and b :: β, supposethereis atypeρof representations of functions of the form f a and their compositions, ... |

298 | Functional programming with bananas, lenses, envelopes and barbed wire
- Meijer, Fokkinga, et al.
- 1991
(Show Context)
Citation Context ...ucture do so as an unfold. In both cases, the structure of the program is determined by the structure of the data it processes. It is natural to consider also compositions of these operations. Meijer =-=[30]-=- coined the term hylomorphism for the composition of a fold after an unfold. The virtual data structure [35] produced by the unfold is subsequently consumed by the fold; the structure of that data det... |

285 | Why Functional Programming Matters
- Hughes
- 1990
(Show Context)
Citation Context ...ulary of discourse, and so on. What distinguishes patterns in functional programming from patterns in object-oriented and other programming paradigms is that the better ‘glue’ available in the for=-=mer [20]-=- allows the patterns to be expressed as abstractions within the language, rather than having to resort to informal prose and diagrams. We use the notation of Haskell [25], the de facto standard lazy f... |

215 | Introduction to Functional Programming using Haskell, 2nd edition - Bird - 1998 |

122 |
Principles of Program Design
- Jackson
- 1975
(Show Context)
Citation Context ...ing lazy evaluation), the second does so with some work, and the third does not permit it at all. 3.1 Reformatting lines The classic application of metamorphisms is for dealing with structure clashes =-=[22]-=-: data is presented in a format that is inconvenient for a particular kind of processing, so it needs to be rearranged into a more convenient format. For example, a piece of text might be presented in... |

105 |
Data structures and program transformation
- Malcolm
- 1990
(Show Context)
Citation Context ...ms, and among other things allows conversion of infinite data representations. Wepresenta theory of metamorphisms and outline some examples. 1 Introduction Folds and unfolds in functional programming =-=[18, 28, 3] a-=-re well-known tools in the programmer’s toolbox. Many programs that consume a data structure follow the pattern of a fold; and dually, many that produce a data structure do so as an unfold. In both ... |

96 |
and Oege de Moor. Algebra of Programming
- Bird
- 1997
(Show Context)
Citation Context ...ms, and among other things allows conversion of infinite data representations. Wepresenta theory of metamorphisms and outline some examples. 1 Introduction Folds and unfolds in functional programming =-=[18, 28, 3] a-=-re well-known tools in the programmer’s toolbox. Many programs that consume a data structure follow the pattern of a fold; and dually, many that produce a data structure do so as an unfold. In both ... |

91 |
Haskell 98 language and libraries: the Revised Report
- Jones, S
- 2003
(Show Context)
Citation Context ...glue’ available in the former [20] allows the patterns to be expressed as abstractions within the language, rather than having to resort to informal prose and diagrams. We use the notation of Haskel=-=l [25]-=-, the de facto standard lazy functional programming language, except that we take the liberty to use some typographic effects in formatting, and to elide some awkwardnesses (such as type coercions and... |

48 | Datatype-generic programming
- Gibbons
- 1999
(Show Context)
Citation Context ... for accessibility we refrain from doing so.) The remaining notation will be introduced as it is encountered. For more examples of the use of these and related patterns in functional programming, see =-=[13]-=-, and for the theory behind this approach to programming, see [12]; for a slightly different view of both, see [3].s4 Jeremy Gibbons 3 Metamorphisms In this section we present three simple examples of... |

48 | The under-appreciated unfold
- Gibbons, Jones
- 1998
(Show Context)
Citation Context ...atterns of computation over such lists are the fold, which consumes a list and produces some value: foldr :: (α → β → β) → β → [α] → β foldr fb[] �= b foldr fb(a : x ) �= fa(foldr =-=fbx)sand the unfold [16], which produces a li-=-st from some seed: unfoldr :: (β → Maybe (α, β)) → β → [α] unfoldr fb�= case fbof Just (a, b ′ ) → a : unfoldr fb ′ Nothing → [] Streaming representation-changers 3 Here, the data... |

46 | A typed lambda calculus with categorical type constructors
- Hagino
- 1987
(Show Context)
Citation Context ...ms, and among other things allows conversion of infinite data representations. Wepresenta theory of metamorphisms and outline some examples. 1 Introduction Folds and unfolds in functional programming =-=[18, 28, 3] a-=-re well-known tools in the programmer’s toolbox. Many programs that consume a data structure follow the pattern of a fold; and dually, many that produce a data structure do so as an unfold. In both ... |

30 | Mongruences and cofree coalgebras
- Jacobs
- 1995
(Show Context)
Citation Context ...ildren.) It is straightforward to generalize the streaming condition to such types: fc= Just (b, c ′ ) ⇒ f (g ca)=Just (b, fmap (λu → gua) c ′ ) (This has been called an ‘τ-invariant’ or=-= ‘mongruence’ [23]-=- elsewhere.) Still, we do not have any useful applications of an unfold to a Generic type after a foldl. 7.2 Related work: Back to basics Some of the ideas presented here appeared much earlier in work... |

28 | Sorting morphisms
- Augusteijn
- 1998
(Show Context)
Citation Context .../4 Then toBase b takes a fraction between zero and one, and converts it into a (possibly infinite) list of digits in base b. For example, toBase 2( 1 /4) =0:unfoldr next2 ( 1 /2) =0:1:unfoldr next2 0==-=[0, 1]-=- Composing fromBase for one base with toBase for another effects a change of base. At first blush, this looks very similar in structure to the reformatting example of Section 3.1. However, now the fol... |

27 | Calculating Functional Programs
- Gibbons
- 2002
(Show Context)
Citation Context ...on will be introduced as it is encountered. For more examples of the use of these and related patterns in functional programming, see [13], and for the theory behind this approach to programming, see =-=[12]-=-; for a slightly different view of both, see [3].s4 Jeremy Gibbons 3 Metamorphisms In this section we present three simple examples of metamorphisms, or representation changers in the form of unfolds ... |

24 | Algebras for Tree Algorithms. D - Gibbons - 1991 |

21 | Proof methods for corecursive programs
- Gibbons, Hutton
- 2005
(Show Context)
Citation Context ...tion holds for f and g, then fc= Just (b, c ′ ) ⇒ f (foldl gcx)=Just (b, foldl gc ′ x ) for all b, c, c ′ and finite lists x.sStreaming representation-changers 13 It also uses the approximatio=-=n lemma [5, 15]. Lemma 6 -=-(Approximation Lemma). For finite, infinite or partial lists x and y, x = y ≡∀n. approx n x = approx n y where approx :: Int → [α] → [α] approx (n +1)[] =[] approx (n +1)(a : x )=a : approx ... |

19 | Generic downwards accumulations - Gibbons - 2000 |

14 |
Exact Real Arithmetic Using Möbius Transformations
- Potts
- 1998
(Show Context)
Citation Context ...the rational functions they represent homographic functions or Möbius transformations. They can be generalized from continued fractions to many other interesting exact representations of real numbers=-= [32], includi-=-ng redundant ones. In fact, the same framework also encompasses radix conversions, as explored in Section 3.2.) By Theorem 3 we then have fromCF = app · foldl (⊛) ident where � q s � � r nq+r... |

11 | Generic Accumulations
- Pardo
- 2002
(Show Context)
Citation Context ... essentially on foldl, which does not generalize in any straightforward way to other datatypes. (We have in the past attempted to show how to generalize scanl to arbitrary datatypes [9–11], and Pard=-=o [31]-=- has improved on these attempts; but we do not see yet how to apply those constructions here.) However, the unfold side of streaming algorithms does generalize easily, to certain kinds of datatype if ... |

9 | Arithmetic coding with folds and unfolds
- Bird, Gibbons
- 2003
(Show Context)
Citation Context ...this reason, we call such fused metamorphisms streaming algorithms; they are the main subject of this paper. We encountered them fortuitously while trying to describe some data compression algorithms =-=[4]-=-, but have since realized that they are an interesting construction in their own right. The remainder of this paper is organized as follows. Section 2 summarizes the theory of folds and unfolds. Secti... |

8 |
Exact real arithmetic with continued fractions
- Vuillemin
- 1990
(Show Context)
Citation Context ...b1 + a2 b2 + b3 + ··· in which all the coefficients are integers. They provide an elegant representation of numbers, both rational and irrational. They have therefore been proposed by various autho=-=rs [2, 17, 24, 38, 26, 27]-=- as a good format in which to carry out exact real arithmetic. Some of the algorithms for simple arithmetic operations on continued fractions can be seen as metamorphisms, and as we shall show here, t... |

7 | The many disguises of accumulation
- Boiten
- 1991
(Show Context)
Citation Context ...ompletely determined the next output, and further inputs are needed in order to make a commitment to that output. For example, consider having consumed the first digit 6 while converting the sequence =-=[6, 7]-=- in decimal (representing 0.6710) to ternary. The fraction 0.610 is about 0.12103; nevertheless, it is not safe to commit to producing the digit 1, because the true result is greater than 0.23, and th... |

7 |
Vuillemin's exact real arithmetic
- Lester
- 1992
(Show Context)
Citation Context ...b1 + a2 b2 + b3 + ··· in which all the coefficients are integers. They provide an elegant representation of numbers, both rational and irrational. They have therefore been proposed by various autho=-=rs [2, 17, 24, 38, 26, 27]-=- as a good format in which to carry out exact real arithmetic. Some of the algorithms for simple arithmetic operations on continued fractions can be seen as metamorphisms, and as we shall show here, t... |

6 | Back to basics: Deriving representation changers functionally
- Hutton, Meijer
- 1993
(Show Context)
Citation Context ... do not have any useful applications of an unfold to a Generic type after a foldl. 7.2 Related work: Back to basics Some of the ideas presented here appeared much earlier in work of Hutton and Meijer =-=[21]-=-. They studied representation changers, consisting of a function followed by the converse of a function. Their representation changers are analogoussStreaming representation-changers 25 to our metamor... |

5 |
Continued Fraction Arithmetic, unpublished manuscript
- Gosper
- 1977
(Show Context)
Citation Context ...b1 + a2 b2 + b3 + ··· in which all the coefficients are integers. They provide an elegant representation of numbers, both rational and irrational. They have therefore been proposed by various autho=-=rs [2, 17, 24, 38, 26, 27]-=- as a good format in which to carry out exact real arithmetic. Some of the algorithms for simple arithmetic operations on continued fractions can be seen as metamorphisms, and as we shall show here, t... |

5 |
Effective continued fractions
- Lester
- 2001
(Show Context)
Citation Context |

4 |
Arbitrary precision arithmetic using continued fractions
- Jones
- 1984
(Show Context)
Citation Context |

2 |
An unbounded spigot algorithm for the digits of π
- Gibbons
- 2003
(Show Context)
Citation Context ...we briefly outline two other applications of streaming; we have described both in more detail elsewhere, and we refer the reader to those sources for the details.s22 Jeremy Gibbons 6.1 Digits of π In=-= [14] -=-we present an unbounded spigot algorithm for computing the digits of π. This work was inspired by Rabinowitz and Wagon [33], who coined the term spigot algorithm for an algorithm that yields output e... |

2 |
A spigot algorithm for the digits of π
- Rabinowitz, Wagon
- 1995
(Show Context)
Citation Context ...ader to those sources for the details.s22 Jeremy Gibbons 6.1 Digits of π In [14] we present an unbounded spigot algorithm for computing the digits of π. This work was inspired by Rabinowitz and Wago=-=n [33], -=-who coined the term spigot algorithm for an algorithm that yields output elements incrementally and does not reuse them after they have been output — so the digits drip out one by one, as if from a ... |