## Generic Programming With Relations and Functors (1999)

Venue: | Journal of Functional Programming |

Citations: | 9 - 6 self |

### BibTeX

@ARTICLE{Bird99genericprogramming,

author = {Richard Bird and Oege De Moor and Paul Hoogendijk},

title = {Generic Programming With Relations and Functors},

journal = {Journal of Functional Programming},

year = {1999},

volume = {6},

pages = {appear,}

}

### OpenURL

### Abstract

This paper explores the idea of generic programming in which programs are parameterised by data types. Part of the constructive theory of lists, specically the part dealing with properties of segments, is generalised in two ways: from lists to arbitrary inductive data types, and from functions to relations. The new theory is used to solve a generic problem about segments. 1 Introduction To what extent is it possible to construct programs without knowing exactly what data types are involved? At rst sight this may seem a strange question, but consider the case of pattern matching. Over lists, this problem can be formulated in terms of two strings, a pattern and a text; the object is to determine if and where the pattern occurs as a segment of the text. Now, pattern matching can be generalised to other data types, including arrays and trees of various kinds; the essential step is to be able to dene the notion of `segment' in these types. So the intriguing question arises: can one...

### Citations

1353 | Introduction to Functional Programming
- Bird, Wadler
- 1988
(Show Context)
Citation Context ...ve a positive answer to the above question, though for a problem somewhat simpler than pattern matching. The problem, the well-known maximum segment sum, was chosen because sucient list theory exists =-=[4, 5, 6]-=- for one to calculate an ecient solution in a few equational steps. It turns out that we can generalise the theory of segments to more or less arbitrary data types, so the calculation leads to a gener... |

221 | An introduction to the theory of lists
- Bird
- 1987
(Show Context)
Citation Context ...ve a positive answer to the above question, though for a problem somewhat simpler than pattern matching. The problem, the well-known maximum segment sum, was chosen because sucient list theory exists =-=[4, 5, 6]-=- for one to calculate an ecient solution in a few equational steps. It turns out that we can generalise the theory of segments to more or less arbitrary data types, so the calculation leads to a gener... |

202 |
Topos Theory
- JOHNSTONE
- 1977
(Show Context)
Citation Context ...et theory can be recovered using just this universal property of powersets, plus the relational calculus. This observation lies at the heart of the categorical approach to sets, the theory of toposes =-=[14, 3-=-, 12]. Below we illustrate how various familiar operators from set theory can be dened in terms of . First of all, it is immediate from the universal property of that id : PA PA satises id = (2). Nex... |

183 | A system of constructor classes: overloading and implicit higherorder polymorphism
- Jones
(Show Context)
Citation Context ... that they can be passed as parameters to generic programs. It seems that research in the design of functional programming languages is also heading in this direction; in particular the work of Jones =-=[15]-=- on constructor classes is relevant in this connection. Acknowledgements Part of this work was done while Oege de Moor visited Roland Backhouse at Eindhoven University. Oege de Moor also wishes to tha... |

107 |
Data structures and program transformation
- Malcolm
- 1990
(Show Context)
Citation Context ...em. In order to be able to construct a generic theory of segments, we need a reformulation of the theory of lists with two new ingredients. Thesrst ingredient is a categorical treatment of data types =-=[18, 19, 17-=-]. In the categorical approach, data types are characterised in terms 1 of certain functors, and specications can be parameterised by functors in a simple and direct manner. The second ingredient invo... |

91 |
Algebraic Approaches to Program Semantics
- Manes, Arbib
- 1986
(Show Context)
Citation Context ...em. In order to be able to construct a generic theory of segments, we need a reformulation of the theory of lists with two new ingredients. Thesrst ingredient is a categorical treatment of data types =-=[18, 19, 17-=-]. In the categorical approach, data types are characterised in terms 1 of certain functors, and specications can be parameterised by functors in a simple and direct manner. The second ingredient invo... |

63 |
A fixpoint theorem for complete categories
- Lambek
- 1968
(Show Context)
Citation Context ... denoted by ([R]), so ([R]) : A T is characterised by (X = R FX ) (X = ([R])): Homomorphisms of the form ([R]) are called catamorphisms [18]. The initial algebra is, in fact, an isomorphism [16] so we can rewrite the above equivalence in the form (X = R FX ) (X = ([R])): The well-known Knaster-Tarski Fixpoint Theorem says that the unique solution (if it exists) of X = F (X ) is also ... |

42 |
A calculus of functions for program derivation
- Bird
- 1987
(Show Context)
Citation Context ...ve a positive answer to the above question, though for a problem somewhat simpler than pattern matching. The problem, the well-known maximum segment sum, was chosen because sucient list theory exists =-=[4, 5, 6]-=- for one to calculate an ecient solution in a few equational steps. It turns out that we can generalise the theory of segments to more or less arbitrary data types, so the calculation leads to a gener... |

26 |
der Woude. A relational theory of datatypes. Available from www.cs.nott.ac.uk/∼rcb/papers
- Aarts, Backhouse, et al.
- 1992
(Show Context)
Citation Context ...terised in terms 1 of certain functors, and specications can be parameterised by functors in a simple and direct manner. The second ingredient involves the move from functions to arbitrary relations [=-=1, -=-8]. Introducing relations enables us to deal more smoothly with non-deterministic specications, but it also turns out that the calculus of relations leads to substantial simplications in the study of ... |

23 |
Toposes, Triples and Theories, volume 278 of Grundleheren der math
- Barr, Wells
- 1985
(Show Context)
Citation Context ... lists, one of which is given by the type declaration lista ::= nil j snoc (lista)a: Formally, this means that lists are represented assnite trees (or terms) over nil and snoc. For instance, the list =-=[1; 2; 3-=-] is represented by the tree snoc (snoc (snoc nil 1)2)3): Thinking of lists purely as trees, we see that a prex of x is really the same thing as a subtree of x . The function subtrees takes a list and... |

14 | Virtual data structures
- Swierstra, Moor
- 1992
(Show Context)
Citation Context ...p as a whole: one can merge the process of its construction and its evaluation. This technique is very common in functional programming; it has been called deforestation by Wadler [21], and Swierstra =-=[20-=-] speaks of virtual data structures. The next lemma shows how deforestation can be used in the present context: 18 Lemma 7 (Deforestation) Let S be a H 0 1 {algebra, and R a H 1 {algebra. Then ([S ]) ... |

13 |
A 2-categorical approach to geometric morphisms
- Carboni, Kelly, et al.
- 1991
(Show Context)
Citation Context ...n functions. More precisely, write J : RelsFun for the inclusion functor of functions into relations. Then for all monotonic functors F; G : RelsRel we have (F = G) (F J = G J): For a proof see [7]=-=-=-. Following Backhouse [1], we will call an endofunctor of Fun a relator if it has a monotonic extension in Rel , and also use this term simply as an abbreviation for a monotonic functor of Rel . 5 Nat... |

9 |
Categories, relations and dynamic programming. D.Phil. thesis
- Moor
- 1992
(Show Context)
Citation Context ...terised in terms 1 of certain functors, and specications can be parameterised by functors in a simple and direct manner. The second ingredient involves the move from functions to arbitrary relations [=-=1, -=-8]. Introducing relations enables us to deal more smoothly with non-deterministic specications, but it also turns out that the calculus of relations leads to substantial simplications in the study of ... |

6 |
Deriving algorithms on binary labelled trees
- Jeuring
- 1989
(Show Context)
Citation Context ...trees in all possible ways: prunings nil = fnilg prunings (bin a x y) = fnilg [ fbin a s t js 2 prunings x ; t 2 prunings yg: The segments of a tree are dened by the same equation as before. Jeuring [=-=13-=-] also considered such a denition, though he spoke of treecuts rather than segments. 3 A calculus of relations Let us now give a brief review of the relational calculus used in the sequel. The calculu... |

4 |
Algebras for Tree Algorithms. DPhil thesis
- Gibbons
- 1991
(Show Context)
Citation Context ... ([ 0 hH 0 !; R H 1 rooti]): Denition (4) is the special case subtrees = bc. As we said before, accumulations are very popular in functional programming, where they are known as scans. Gibbons [11] has made a study of scans on a particular species of binary tree. Intuitively, the accumulation bRc implements the evaluation of the catamorphism ([R]) on all subtrees of its argument. This is the co... |

4 |
Topoi : The Categorial Analysis of Logic. Volume 98
- Goldblatt
- 1979
(Show Context)
Citation Context ...et theory can be recovered using just this universal property of powersets, plus the relational calculus. This observation lies at the heart of the categorical approach to sets, the theory of toposes =-=[14, 3-=-, 12]. Below we illustrate how various familiar operators from set theory can be dened in terms of . First of all, it is immediate from the universal property of that id : PA PA satises id = (2). Nex... |

4 |
Algebraic speci of data types: a synthetic approach
- Lehmann, Smyth
- 1981
(Show Context)
Citation Context ...em. In order to be able to construct a generic theory of segments, we need a reformulation of the theory of lists with two new ingredients. Thesrst ingredient is a categorical treatment of data types =-=[18, 19, 17-=-]. In the categorical approach, data types are characterised in terms 1 of certain functors, and specications can be parameterised by functors in a simple and direct manner. The second ingredient invo... |

2 |
Commuting relators. Technical Report. Available by anonymous ftp from ftp.win.tue.nl, directory pub/math.prog.construction
- Backhouse, Doornbos, et al.
- 1992
(Show Context)
Citation Context ...ely to benet by the work of Backhouse [1], who has shown how many theorems about regular algebra can be generalised to data types. Backhouse and his team have also developed a generic theory of zips [=-=2]-=-. Finally, another important direction for future research is the design of a programming language in which data types aresrst-class citizens, in the sense that they can be passed as parameters to gen... |

1 |
Working notes on membership of data types. Unpublished manuscript
- Moor
- 1993
(Show Context)
Citation Context ...erpretation of this equation is 8a : a2 F x : aRb 9y : x (FR)y ^ (8b 0 : b 0 2 F y : b 0 = b): Oursrst result about membership says that the above equation has at most one solution. For a proof see [=-=9]-=- (where proofs of most of the following facts about membership can be found). Lemma 1 If 2 F is a membership relation of F , then 2 F is the largest natural transformation of type ids- F. To illustrat... |