## Bananas in Space: Extending Fold and Unfold to Exponential Types (1995)

### Cached

### Download Links

- [www.cs.nott.ac.uk]
- [research.microsoft.com]
- [research.microsoft.com]
- [www.cs.nott.ac.uk]
- CiteULike
- DBLP

### Other Repositories/Bibliography

Citations: | 95 - 6 self |

### BibTeX

@INPROCEEDINGS{Meijer95bananasin,

author = {Erik Meijer and Graham Hutton},

title = {Bananas in Space: Extending Fold and Unfold to Exponential Types},

booktitle = {},

year = {1995},

pages = {324--333},

publisher = {ACM Press}

}

### Years of Citing Articles

### OpenURL

### Abstract

Fold and unfold are general purpose functionals for processing and constructing lists. By using the categorical approach of modelling recursive datatypes as fixed points of functors, these functionals and their algebraic properties were generalised from lists to polynomial (sum-of-product) datatypes. However, the restriction to polynomial datatypes is a serious limitation: it precludes the use of exponentials (functionspaces) , whereas it is central to functional programming that functions are first-class values, and so exponentials should be able to be used freely in datatype definitions. In this paper we explain how Freyd's work on modelling recursive datatypes as fixed points of difunctors shows how to generalise fold and unfold from polynomial datatypes to those involving exponentials. Knowledge of category theory is not required; we use Gofer throughout as our meta-language, making extensive use of constructor classes. 1 Introduction During the 1980s, Bird and Meertens [6, 22] d...

### Citations

1311 | Introduction to Functional Programming
- Bird, Wadler
- 1988
(Show Context)
Citation Context ...ponentials. Knowledge of category theory is not required; we use Gofer throughout as our meta-language, making extensive use of constructor classes. 1 Introduction During the 1980s, Bird and Meertens =-=[6, 22]-=- developed a calculus (nicknamed Squiggol) of recursion functionals on lists, using which efficient functional programs can be derived from specifications by using equational reasoning. Squiggol was s... |

1118 |
The Lambda Calculus: its Syntax and Semantics
- Barendregt
- 1984
(Show Context)
Citation Context ...a function n2d that extracts the list of digits from a number: n2d :: Int -? [Int] n2d = exec . ana ("x -? if x != 9 then Done x else Pause x ("n -? [n `div` 10, n `mod` 10])) For example, n=-=2d 1234 = [1; 2; 3; 4]-=-. A more practical use of the type State is the extension of a library of parsing combinators [15] with a combinator for parallel composition of parsers [9]. 3.2 Contravariant uses of (-?) An example ... |

401 | Deforestation: Transforming programs to eliminate trees
- Wadler
- 1990
(Show Context)
Citation Context ...hi . ana psi A straightforward fixed point induction shows that the two constituents of a hylomorphism can be fused together to give a direct recursive definition that avoids building an intermediate =-=[37] (or -=-virtual [35]) value: hylo phi psi = phi . map (hylo phi psi) . psi For example, if we express fix as a hylomorphism rather than the composition of a cata and an ana, fix f = hylo ("(Cons f x) -? ... |

364 |
Types, abstraction and parametric polymorphism
- Reynolds
- 1983
(Show Context)
Citation Context ...neral discussion of free theorems in the context of class restrictions.) This result is a generalisation to the untyped -calculus of Reynolds' (functional) abstraction theorem for the typed -calculus =-=[31]-=-. Appealing to the abstraction theorem with a = Scott, b = Cont and h = up, we are required to find a retract from Cont to Scott satisfying the preconditions of the theorem. Using the fact that Scott ... |

330 | Theorems for Free
- WADLER
- 1989
(Show Context)
Citation Context ... the expected behaviour: eval (In x) = case x of Num n -? n Add e e' -? (eval e) + (eval e') 2.3 Free theorems and fusion A useful heuristic in functional programming is to inspect the "free theo=-=rem" [36]-=- that comes from the type of a polymorphic function. The free theorem for cata :: Functor f =? (f a -? a) -? (Rec f -? a) is the well-known fusionslaw [27]: for strict functions h, h.phi = phi'.(map h... |

326 |
Denotational Semantics: A Methodology For Language Development
- Schmidt
- 1986
(Show Context)
Citation Context ...volving exponentials, and elaborates on the problems with such datatypes. 3.1 Covariant uses of (-?) An example in which function-spaces are used covariantly is that of non-deterministic computations =-=[32]-=-. An element of datatype State a b is either a final value of type b, or an intermediate state of type a together with a non-deterministic continuation of type a -? [State a b]: data S a b s = Done b ... |

301 | Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire
- MEIJER, FOKKINGA, et al.
- 1991
(Show Context)
Citation Context ...hese functionals. The theory and practice of such generic functionals has been explored by many authors, e.g. [3, 7, 10, 13, 14, 24, 33]. The aim of the bananas paper of Meijer, Fokkinga and Paterson =-=[27]-=- was to bring the ideas of Squiggol closer to lazy functional languages. This was achieved by moving from the category set of sets and total functions (the world of standard category theory and Squigg... |

238 | The lazy lambda calculus
- ABRAMSKY
- 1989
(Show Context)
Citation Context ...a function n2d that extracts the list of digits from a number: n2d :: Int -? [Int] n2d = exec . ana ("x -? if x != 9 then Done x else Pause x ("n -? [n `div` 10, n `mod` 10])) For example, n=-=2d 1234 = [1; 2; 3; 4]-=-. A more practical use of the type State is the extension of a library of parsing combinators [15] with a combinator for parallel composition of parsers [9]. 3.2 Contravariant uses of (-?) An example ... |

179 | A system of constructor classes: overloading and implicit higher-order polymorphism
- Jones
- 1993
(Show Context)
Citation Context ...mial datatypes to those involving exponentials. We use Gofer throughout as our meta-language, making extensive use of the constructor classes extension to the standard Gofer (or Haskell) class system =-=[17, 19]-=-. Using Gofer rather than category theory as our meta-language makes the concepts more accessible as well as executable, and eliminates the gap between theory and practice. 2 Polynomial datatypes We b... |

111 | A fold for all seasons
- Sheard, Fegaras
- 1993
(Show Context)
Citation Context ...aic laws that can be used to derive, transform and reason about programs expressed using these functionals. The theory and practice of such generic functionals has been explored by many authors, e.g. =-=[3, 7, 10, 13, 14, 24, 33]-=-. The aim of the bananas paper of Meijer, Fokkinga and Paterson [27] was to bring the ideas of Squiggol closer to lazy functional languages. This was achieved by moving from the category set of sets a... |

98 | Higher-order functions for parsing
- Hutton
- 1992
(Show Context)
Citation Context ... if x != 9 then Done x else Pause x ("n -? [n `div` 10, n `mod` 10])) For example, n2d 1234 = [1; 2; 3; 4]. A more practical use of the type State is the extension of a library of parsing combina=-=tors [15]-=- with a combinator for parallel composition of parsers [9]. 3.2 Contravariant uses of (-?) An example where (-?) is used contravariantly is in the definition of a fixed point combinator by using recur... |

97 |
and Order in Algorithmics
- Law
- 1992
(Show Context)
Citation Context ...aic laws that can be used to derive, transform and reason about programs expressed using these functionals. The theory and practice of such generic functionals has been explored by many authors, e.g. =-=[3, 7, 10, 13, 14, 24, 33]-=-. The aim of the bananas paper of Meijer, Fokkinga and Paterson [27] was to bring the ideas of Squiggol closer to lazy functional languages. This was achieved by moving from the category set of sets a... |

96 |
de Moor, O.: Algebras of Programming
- Bird
- 1996
(Show Context)
Citation Context ...aic laws that can be used to derive, transform and reason about programs expressed using these functionals. The theory and practice of such generic functionals has been explored by many authors, e.g. =-=[3, 7, 10, 13, 14, 24, 33]-=-. The aim of the bananas paper of Meijer, Fokkinga and Paterson [27] was to bring the ideas of Squiggol closer to lazy functional languages. This was achieved by moving from the category set of sets a... |

95 |
Algorithmics | towards programming as a mathematical activity
- Meertens
- 1986
(Show Context)
Citation Context ...ponentials. Knowledge of category theory is not required; we use Gofer throughout as our meta-language, making extensive use of constructor classes. 1 Introduction During the 1980s, Bird and Meertens =-=[6, 22]-=- developed a calculus (nicknamed Squiggol) of recursion functionals on lists, using which efficient functional programs can be derived from specifications by using equational reasoning. Squiggol was s... |

92 |
Algebraically complete categories
- Freyd
- 1990
(Show Context)
Citation Context ...perator can also be defined as the composition of an ana followed by a cata, thus providing the full power of recursion. (We have since discovered that this observation has already been made by Freyd =-=[11]-=-.) The effect is that algebraic languages that provide cata and ana as the only means to define recursive functions are not limited in expressive power. Using cata and ana, the least fixed point fix f... |

86 |
Algebraic Approaches to Program Semantics
- Manes, Arbib
- 1986
(Show Context)
Citation Context ...easoning. Squiggol was subsequently generalised from lists to polynomial (sumof -product) datatypes [20] by using the categorical approach of modelling recursive datatypes as fixed points of functors =-=[21, 14]-=-. This approach allows foldr, unfold and other recursion functionals to be uniformly generalised from lists to polynomial datatypes. The generalised functionals are given special names (such as catamo... |

84 |
Algebraic data types and program transformation
- Malcolm
- 1990
(Show Context)
Citation Context ..., using which efficient functional programs can be derived from specifications by using equational reasoning. Squiggol was subsequently generalised from lists to polynomial (sumof -product) datatypes =-=[20]-=- by using the categorical approach of modelling recursive datatypes as fixed points of functors [21, 14]. This approach allows foldr, unfold and other recursion functionals to be uniformly generalised... |

68 |
Recursive types reduced to induct,ive types
- Freyd
- 1990
(Show Context)
Citation Context ...eved by moving from the category set of sets and total functions (the world of standard category theory and Squiggol) to the category cpo of cpos and continuous functions (the world of cpo-categories =-=[12]-=- and lazy functional programming). However, a serious deficiency of the bananas paper --- and more generally, the work of the Squiggol community --- is its limitation to polynomial datatypes [20]. Thi... |

46 |
On the relation between direct and continuation semantics
- Reynolds
- 1974
(Show Context)
Citation Context ...p` g) `dimap` f) `dimap` ((g `dimap` f) `dimap` g)) h) type Closure = Rec C Suppose now that we want to show that the continuationbased interpreter is correct with respect to the standard interpreter =-=[30]-=-. An interpreter based upon a reflexive type b is correct with respect to an interpreter based upon a reflexive type a if there exists a retract from b to a such that the following diagram commutes fo... |

43 |
Calculating Compilers
- Meijer
- 1992
(Show Context)
Citation Context |

34 |
The category theoretic solution of recursive domain equations
- Smyth, Plotkin
- 1982
(Show Context)
Citation Context ...ment. A standard solution to the problem is to move from the category cpo to the category cpo ep of cpos and embeddingprojection pairs, on which category the exponential functor can be made covariant =-=[34]-=-. But while the setting of cpo ep is technically sufficient, from a practical point of view it is not a convenient category upon which to base a programming calculus for reasoning about datatypes and ... |

32 |
Category theoretic approach to data types
- Hagino
- 1987
(Show Context)
Citation Context ...easoning. Squiggol was subsequently generalised from lists to polynomial (sumof -product) datatypes [20] by using the categorical approach of modelling recursive datatypes as fixed points of functors =-=[21, 14]-=-. This approach allows foldr, unfold and other recursion functionals to be uniformly generalised from lists to polynomial datatypes. The generalised functionals are given special names (such as catamo... |

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

23 |
der Woude. A relational theory of datatypes
- Aarts, Backhouse, et al.
- 1992
(Show Context)
Citation Context |

15 | Relational properties of recursively defined domains
- Pitts
- 1993
(Show Context)
Citation Context ... [12]. His key idea is to model recursive datatypes as fixed points of difunctors, functors on two variables, contravariant on the first, covariant on the second. In the present article (but see also =-=[29, 28]-=-) we explain to functional programmers how Freyd's work shows how to generalise fold and unfold from polynomial datatypes to those involving exponentials. We use Gofer throughout as our meta-language,... |

11 | More advice on proving a compiler correct: Improve a correct compiler
- Meijer
- 1994
(Show Context)
Citation Context ... the stack, i.e. for all finite expressionsse :: Expr we have push (eval e) = eval' e, can easily be proved using fusion and the distribution of push over addition: push (a+b) = add.(push a).(push b) =-=[25]-=-. 2.4 Coalgebras and anamorphisms Using cata we can define functions with recursive datatypes as their source. Dually, it is also useful to have a functional for defining functions with recursive data... |

6 |
Programming Languages and Their Definition, volume 177
- Bekič
- 1984
(Show Context)
Citation Context ...finition of Rec.) Mutually recursive datatypes can be reduced to direct recursive datatypes in a similar way to that in which mutually recursive functions can be reduced to direct recursive functions =-=[5, 10]-=-. So no generality is lost by restricting our attention to direct recursive datatypes. Note that only the type constructor part of a functor is necessary to express datatypes as fixed points of functo... |

5 |
Modelling office processes with functional parsers
- Florijn
- 1994
(Show Context)
Citation Context ...mod` 10])) For example, n2d 1234 = [1; 2; 3; 4]. A more practical use of the type State is the extension of a library of parsing combinators [15] with a combinator for parallel composition of parsers =-=[9]-=-. 3.2 Contravariant uses of (-?) An example where (-?) is used contravariantly is in the definition of a fixed point combinator by using recursion on types rather than recursion on functions. We first... |

5 |
Gofer goes bananas
- Meijer, Jones
- 1994
(Show Context)
Citation Context ...mial datatypes to those involving exponentials. We use Gofer throughout as our meta-language, making extensive use of the constructor classes extension to the standard Gofer (or Haskell) class system =-=[17, 19]-=-. Using Gofer rather than category theory as our meta-language makes the concepts more accessible as well as executable, and eliminates the gap between theory and practice. 2 Polynomial datatypes We b... |

4 |
Gofer 2.28 release notes
- Jones
- 1993
(Show Context)
Citation Context ..., pp mapP :: Functor f =? (a -? b) -? (P f a -? P f b) mapP g = map ("(x,a) -? (x, g a)) instance Functor f =? Functor (P f) where map = mapP Note that P above is defined as a restricted type syn=-=onym [16]-=- so that it can be partially applied. As a consequence, the functional mapP cannot be defined directly within the instance declaration for P f. A functional para that builds paramorphisms is defined n... |

3 |
Control structures from types
- Paterson
- 1994
(Show Context)
Citation Context ...tant area for future research is in experimenting with the use of the generalised operators and laws in writing and transforming programs. Another interesting topic for study is non-regular datatypes =-=[28]-=-, i.e. datatypes in which the recursive calls in the body are not all of the form of the head of a definition. Examples are the datatype Twist a b of lists of alternating elements of type a and type b... |

2 |
Type classes for better free theorems
- Meijer
- 1994
(Show Context)
Citation Context ...ctable conditions that establish the correctness of one interpreter with respect to another: h (f `apply` a) = (h f) `apply` (h a) h.g = f.h ) h (abstr g) = abstr f ) h.(eval e) = (eval e).map h (See =-=[26]-=- for a general discussion of free theorems in the context of class restrictions.) This result is a generalisation to the untyped -calculus of Reynolds' (functional) abstraction theorem for the typed -... |

1 |
Gofer 2.28 release notes. February
- Jones
- 1993
(Show Context)
Citation Context ..., pp mapP :: Functor f => (a -> b) -> (P f a -> P f b) mapP g = map (\(x,a) -> (x, g a)) instance Functor f => Functor (P f) where map = mapP Note that P above is defined as a restricted type synonym =-=[16]-=- so that it can be partially applied. As a consequence, the functional mapP cannot be defined directly within the instance declaration for P f. A functional para that builds paramorphisms is defined n... |

1 | The Lambda Calculus – it’s Syntax and Semantzcs. North-Hollandj - Barendregt - 1984 |

1 | Programming Languages and thew Dejinztzon, volume 177 of LNCS - BekiL - 1984 |

1 | An Intr-oducttorz to Funchord Programming - Bird, Wadler - 1988 |