## Polytypic Programming With Ease (1999)

### Cached

### Download Links

- [www.informatik.uni-bonn.de]
- [www.cs.bonn.edu]
- [www.informatik.uni-bonn.de]
- DBLP

### Other Repositories/Bibliography

Citations: | 13 - 5 self |

### BibTeX

@MISC{Hinze99polytypicprogramming,

author = {Ralf Hinze},

title = {Polytypic Programming With Ease},

year = {1999}

}

### OpenURL

### Abstract

A functional polytypic program is one that is parameterised by datatype. Since polytypic functions are defined by induction on types rather than by induction on values they typically operate on a higher level of abstraction than their monotypic counterparts. However, polytypic programming is not necessarily more complicated than conventional programming. We show that a polytypic function is uniquely defined by its action on constant functors, projection functors, sums, and products. This information is sufficient to specialize a polytypic function to arbitrary polymorphic datatypes, including mutually recursive datatypes and nested datatypes. The key idea is to use infinite trees as index sets for polytypic functions and to interpret datatypes as algebraic trees. This approach appears both to be simpler, more general, and more efficient than previous ones which are based on the initial algebra semantics of datatypes. Polytypic functions enjoy polytypic properties. We show that well-kno...

### Citations

1312 | Constructive functional programming
- Bird
- 1989
(Show Context)
Citation Context ...hGiis; which is an immediate consequence of Proposition 3, shows that reduce n combines a reduction with a map. This idiom is, in fact, a very old one. It appears, for instance, in R. Bird's lectures =-=[6]-=- where it is shown that each homomorphism on lists (that is, each catamorphism) can be expressed in this form. In a sense, reduce n can be seen as a generalization of that scheme. Specializing Proposi... |

458 | Comprehending Monads
- Wadler
- 1990
(Show Context)
Citation Context ...of fmap is the so-called monadic map [8]. Before we discuss its denition let us brie y review the basics of monads. For a more in-depth treatment we refer the interested reader to P. Wadler's papers [=-=24, 25, 26]-=-. One can think of a monad as an abstract type for computations. In Haskell monads are captured by the following class declaration. class Monad m where return :: a ! m a (>>=) :: m a ! (a ! m b) ! m b... |

321 |
A Compendium of Continuous Lattices
- Gierz, Hofmann, et al.
- 1980
(Show Context)
Citation Context ... types since `!' is contravariant in itssrst argument: (!) :: (a 0 ! a) ! (b ! b 0 ) ! ((a ! b) ! (a 0 ! b 0 )) (' 1 ! ' 2 ) h = ' 2shs' 1 : Now, drawing from the theory of embeddings and projections [9] we can remedy the situation as follows. The central idea is to supply a pair of functions ({; ), where is the left-inverse of {, that is, s{ = id . If the functions additionally satisfy {s v id ... |

302 | Functional programming with bananas, lenses, envelopes and barbed wire
- Meijer, Fokkinga, et al.
- 1991
(Show Context)
Citation Context ...Rosei corresponds to thesrst, less ecient denition of sizer . Unlike the framework we have presented so far PolyP allows the programmer to dene general recursion schemes like cata- and anamorphisms [2=-=-=-0]. As an example, the recursion scheme cata , which is used in size , is given by catahF i :: 8a b:(F 0 a b ! b) ! (F a ! b) catahBi ' = 'sbmaphBi id (catahBi ')sout : The operation (-) 0 , which is ... |

228 | Purely Functional Data Structures
- Okasaki
- 1998
(Show Context)
Citation Context ...nctor Perfect is an example of a non-regular or nested functor, which is interpreted by an algebraic functor tree. Sequ = K1+ Sequ + Id Sequ Tree23 = Fst + Tree23 (Node23 ; Snd) C. Okasaki [22] uses the functor Sequ as the basis for a sequence implementation with an ecient indexing operation. The functor Tree23 models 2-3 trees. The novelty of this denition is that the data-structural inva... |

215 |
Introduction to Functional Programming using Haskell, 2nd edition
- Bird
- 1998
(Show Context)
Citation Context ... asrst example, consider the datatype of rose trees. data Rose a = Branch a (List (Rose a)) data List a = Nil j Cons a (List a) The size of a rose tree can be determined as follows, see, for instance =-=[2]-=-. sizer :: Rose a ! Int sizer (Branch a ts) = 1 + suml (list sizer ts) list :: (a ! a 0 ) ! (List a ! List a 0 ) list ' Nil = Nil list ' (Cons a as) = Cons (' a) (list ' as) 2 suml :: List Int ! Int s... |

175 | PolyP - a polytypic programming language extension
- Jansson, Jeuring
- 1997
(Show Context)
Citation Context ... a new framework for a polytypic extension of functional programming languages such as Haskell or Standard ML. The framework is simpler, more general, and more ecient than previous ones such as PolyP =-=[14-=-] that are based on the initial algebra semantics of datatypes. A polytypic function is one that is dened by induction on the structure of types. The archetypical example of a polytypic function is si... |

97 | Dynamic Typing in Polymorphic Languages
- Abadi, Cardelli, et al.
- 1992
(Show Context)
Citation Context ...argument, which is itself a type (or possibly, the encoding of a type). Even if we circumvented this problem by using encodings into a universal datatype [27] or by using dynamic types and a typecase =-=[1]-=-, the result would be rather inecient because poly would interpret its type argument at each stage of the recursion. By specializing polyhJF Ki for a given F we remove this interpretative layer. Thus,... |

96 |
de Moor, O.: Algebras of Programming
- Bird
- 1996
(Show Context)
Citation Context ... main text. The notation is fairly standard so the cognoscenti should have no problems in reading the article. For background material the reader is referred to the textbook by R. Bird and O. de Moor =-=[3]-=-. Standard combinators id is the identity function, `' denotes functional composition, and const creates a constant-valued function. id :: a ! a id x = x () :: (b ! c) ! (a ! b) ! (a ! c) (fsg) x = f ... |

95 | A new approach to generic functional programming
- Hinze
- 1999
(Show Context)
Citation Context ...der polymorphism [18]. Currently, the author is working on an extension so that polytypic functions can be dened generically for all datatypes expressible in Haskell. First results are summarized in [=-=12-=-]. An application of polytypic programming to digital searching is described in a companion paper [11], where we show how to dene tries and operations on tries generically for arbitrary datatypes ofsr... |

88 | Algebra of programming - Bird, Moor - 1997 |

79 | Nested datatypes
- BIRD, MEERTENS
- 1998
(Show Context)
Citation Context ...l on the right-hand side, Perfect (Node a k) k , is not identical to the left-hand side of the equation: Perfect is an example of a so-called nested datatype, a term coined by R. Bird and L. Meertens =-=[5]-=-. Since Perfect only encompasses perfect binary search trees, the size of a tree of type Perfect a a can be computed in logarithmic time. sizep :: Perfect a k ! Int sizep (Zero a) = 1 sizep (Succ t) =... |

69 | Functional Programming with Overloading and Higher-Order Polymorphism
- Jones
- 1995
(Show Context)
Citation Context ...an be dened as follows. subtermshT i :: T ! List T subtermshT i =sattenhT 0 isout A direction for future work suggests itself: it remains to broaden the approach to include higher-order polymorphism [=-=18-=-]. Currently, the author is working on an extension so that polytypic functions can be dened generically for all datatypes expressible in Haskell. First results are summarized in [12]. An application ... |

49 | Merging monads and folds for functional programming
- Meijer, Jeuring
- 1995
(Show Context)
Citation Context ...usly except that in the denition of `' the computations h 1 x 1 and h 2 x 2 are reversed. For applications of monadic maps we refer the interested reader to the tutorial of E. Meijer and J. Jeuring [2=-=1]-=-. 6.2 Reductions The functions size, sum, andsatten are instances of a more general concept, due to L. Meertens [19], termed reduction or crush. A reduction is a function of type F a ! a that collapse... |

42 | Encoding types in ML-Like languages
- Yang
(Show Context)
Citation Context ...mply that the type of poly depends on thesrst argument, which is itself a type (or possibly, the encoding of a type). Even if we circumvented this problem by using encodings into a universal datatype =-=[27]-=- or by using dynamic types and a typecase [1], the result would be rather inecient because poly would interpret its type argument at each stage of the recursion. By specializing polyhJF Ki for a given... |

41 | Calculate polytypically
- Meertens
- 1996
(Show Context)
Citation Context ...dic maps we refer the interested reader to the tutorial of E. Meijer and J. Jeuring [21]. 6.2 Reductions The functions size, sum, andsatten are instances of a more general concept, due to L. Meertens =-=[19-=-], termed reduction or crush. A reduction is a function of type F a ! a that collapses a structure of values of type a into a single value of type a. To dene a reduction two ingredients are required: ... |

31 | Generalizing generalized tries
- Hinze
(Show Context)
Citation Context ...ity and comparison functions, mapping and zipping functions, pretty printers (such as Haskell's show function), parsers (such as Haskell's read function), data compression [17], and digital searching =-=[-=-11]. The ability to dene such programs generically for all datatypes greatly simplies the construction and maintenance of software systems. Since polytypic functions are dened by induction on types ra... |

24 | Fundamental properties of infinite trees, Theoretical Computer Science 25 - Courcelle - 1983 |

22 | Polytypic compact printing and parsing
- JANSSON, JEURING
- 1999
(Show Context)
Citation Context ...pical examples include equality and comparison functions, mapping and zipping functions, pretty printers (such as Haskell's show function), parsers (such as Haskell's read function), data compression =-=[-=-17], and digital searching [11]. The ability to dene such programs generically for all datatypes greatly simplies the construction and maintenance of software systems. Since polytypic functions are de... |

21 |
Fundamental properties of in trees
- Courcelle
- 1983
(Show Context)
Citation Context ...ries This section introduces basic notions and facts from the theory of innite trees as needed in the subsequent sections. For a more detailed survey the reader is referred to B. Courcelle's article [=-=7]-=-, which also contains further references. A ranked set is a family ( F k j k 2 N ) of pairwise disjoint sets F k of symbols of rank (or arity) k. Given a ranked set F of function symbols we denote by ... |

19 | Monadic Maps and Folds for Arbitrary Datatypes
- Fokkinga
- 1994
(Show Context)
Citation Context ...that ' ! (mapE hGi '; mapE hGi ' ) is the functorial action of G in the category CPO E of complete partial orders and embedding-projection pairs. Another variant of fmap is the so-called monadic map [=-=8-=-]. Before we discuss its denition let us brie y review the basics of monads. For a more in-depth treatment we refer the interested reader to P. Wadler's papers [24, 25, 26]. One can think of a monad a... |

18 |
Oege de Moor, and Paul Hoogendijk. Generic functional programming with types and relations
- Bird
- 1996
(Show Context)
Citation Context ...P. Jansson and J. Jeuring [15], for instance, requires a function that determines the immediate subterms of a term. A similar function appears in the article of R. Bird, O. de Moor, and P. Hoogendijk =-=[4]-=-, who present a generalization of the maximum segment sum problem. In both cases the recursive structure of a datatype must be known. Now, since our framework deals with type recursion on the meta lev... |

15 |
de Moor O
- Bird
- 1996
(Show Context)
Citation Context ... main text. The notation is fairly standard so the cognoscenti should have no problems in reading the article. For background material the reader is referred to the textbook by R. Bird and O. de Moor =-=[3]-=-. Standard combinators id is the identity function, ‘◦’ denotes functional composition, and const creates a constant-valued function. id :: a → a id x = x (◦) :: (b→c) → (a → b) → (a → c) (f ◦ g) x = ... |

15 | Generic functional programming with types and relations - Bird, Moor, et al. - 1996 |

13 | Polytypic functions over nested datatypes
- Hinze
- 1999
(Show Context)
Citation Context ... could be generalized to arbitrary monads that contain a zero element such as fail . 7 Related and Future Work This article can be regarded as a successor to my previous work on polytypic programming =-=[10-=-], where a similar approach using rational trees is presented. The major dierence between the two frameworks lies in the treatment of functor composition. In the `rational tree approach' functor compo... |

13 | Functional pearl: Polytypic unification - Jansson, Jeuring - 1998 |

12 | Polytypic programming. Pages 68--114 of - Jeuring - 1996 |

9 |
PolyLib—A library of polytypic functions
- Jansson, Jeuring
- 1998
(Show Context)
Citation Context ... redhF 2 i redhF 1 F 2 i = uncurry ops(redhF 1 i redhF 2 i) A number of useful functions can be implemented in terms of reduce and fmap , see Figure 2. L. Meertens [19], P. Jansson and J. Jeuring [1=-=6]-=- give further applications. Again, it is interesting to inspect the subsidiary functions reduce n given by reduce n hhGii e op = red n hhGii more closely. The following property reduce n hhGii e op ('... |

9 | Nested datatypes. Pages 52–67 of - Bird, Meertens - 1998 |

7 | international conference on mathematics of program construction - Fourth |

4 |
Functional pearl: Polytypic uni
- Jansson, Jeuring
- 1998
(Show Context)
Citation Context ...f PolyLib [16] can be implemented in our framework, except, of course, cata- and anamorphisms|it is indispensable for others. The polytypic unication algorithm described by P. Jansson and J. Jeuring [=-=15]-=-, for instance, requires a function that determines the immediate subterms of a term. A similar function appears in the article of R. Bird, O. de Moor, and P. Hoogendijk [4], who present a generalizat... |

3 |
A note on inconsistencies caused by in a cartesian closed category. Theoretical Computer Science
- Huwig, Poigne
- 1990
(Show Context)
Citation Context ... g)sInl = f (f O g)sInr = g hs(f O g) = (hsf ) O (hsg) if h is strict: Note that, for fundamental reasons, `+' is not a categorical coproduct in nonstrict languages such as Haskell, see, for instance =-=-=-[13]. Products Products are given by the following datatype. 2 data a b = (a; b) outl :: a b ! a outl (x ; y) = x outr :: a b ! b outr (x ; y) = y (O) :: (c ! a) ! (c ! b) ! (c ! a b) (f M g) z = ... |

1 | b) → c) → (a → b → c) curry f x y = f (x, y) uncurry :: (a → b → c) → ((a, b) → c) uncurry f (x, y) = fxy - curry |

1 | eds), Informal proceedings workshop on generic programming - Backhouse - 1998 |