## PolyLib - a library of polytypic functions (1998)

Venue: | In Workshop on Generic Programming (WGP'98), Marstrand |

Citations: | 4 - 0 self |

### BibTeX

@INPROCEEDINGS{Jansson98polylib-,

author = {Patrik Jansson and Johan Jeuring},

title = {PolyLib - a library of polytypic functions},

booktitle = {In Workshop on Generic Programming (WGP'98), Marstrand},

year = {1998},

pages = {14--255},

publisher = {Springer-Verlag}

}

### OpenURL

### Abstract

This paper describes the polytypic functions in PolyLib, motivates their presence in the library, and gives a rationale for their design. Thus we hope to share our experience with other researchers in the field. We will assume the reader has some familiarity with the field of polytypic programming. Of course, a library is an important part of a programming language. Languages like Java, Delphi, Perl and Haskell are popular partly because of their useful and extensive libraries. For a polytypic programming language it is even more important to have a clear and well-designed library: writing polytypic programs is difficult, and we do not expect many programmers to write polytypic programs. On the other hand, many programmers use polytypic programs such as parser generators, equality functions, etc. This is a first attempt to describe the library of PolyP; we expect that both the form and content of this description will change over time. One of the goals of this paper is to obtain feedback on the library design from other researchers working within the field. At the moment the library only contains the basic

### Citations

5292 |
Design Patterns: Elements of Reusable Object-Oriented Software
- Gamma, Helm, et al.
- 1994
(Show Context)
Citation Context ...cture itself. Also known as: PolyLib Functorial ML [1] Squiggol charity [3] cata i fold 1 i (jij) ----- i --- ana o - [(o)] (--- o ---) Functions cata and para are instances of the Visitor pattern in =-=[5]-=-. Known uses: Very many polytypic functions are dened using cata: pmap, crush, thread, flatten, propagate, and all our applications use it. Function para is used in rewrite. Background: The catamorphi... |

216 |
An introduction to the theory of lists
- Bird
- 1987
(Show Context)
Citation Context ...is used in the denition of pmap, cata, ana, hylo, para and in many other PolyLib functions. Background: The map function was one of the rst combinators distinguished in the work of Bird and Meertens, =-=[2, 16]-=-. The traditional map in functional languages maps a function over a list of elements. The current Haskell version of map is overloaded: 3 map :: Functor f =? (a-?b) -? f a -? f b and can be used as t... |

175 | PolyP — a polytypic programming language extension
- Jansson, Jeuring
- 1997
(Show Context)
Citation Context ...type constructors to obtain polytypic functionss[12]. A polytypic function is dened either by induction on the structure of regular 1 type constructors or in terms of other polytypic functions. PolyP =-=[8]-=- is an extension of the functional programming language Haskell with a construct for dening polytypic functions. PolyP is a type guided preprocessor that generates instances of polytypic functions and... |

105 |
Data structures and program transformation
- Malcolm
- 1990
(Show Context)
Citation Context ...n rewrite. Background: The catamorphism, cata, is the generalisation of the Haskell function foldr and the anamorphism, ana, is the (category theoretic) dual. Catamorphisms were introduced by Malcolm =-=[14, 15]-=-. A hylomorphism is the fused composition of a catamorphism and an anamorphism specied by: hylo i o = cata i . ana o. The paramorphism [17], para, is the elimination rule for the type d a from type th... |

95 |
Algorithmics | towards programming as a mathematical activity
- Meertens
- 1986
(Show Context)
Citation Context ...is used in the denition of pmap, cata, ana, hylo, para and in many other PolyLib functions. Background: The map function was one of the rst combinators distinguished in the work of Bird and Meertens, =-=[2, 16]-=-. The traditional map in functional languages maps a function over a list of elements. The current Haskell version of map is overloaded: 3 map :: Functor f =? (a-?b) -? f a -? f b and can be used as t... |

92 | Polytypic programming
- Jeuring, Jansson
- 1996
(Show Context)
Citation Context ...herwise. The member functions of the class Term can all be generated polytypically for every regular datatype so unify is also polytypic. ffl Given a unication function, rewriting is not far away: in =-=[13]-=- we give an implementation of a function rewrite rewrite :: Term t =? [(t,t)] -? t -? t that takes a list of rewrite rules (pairs of terms containing variables) and a term and rewrites the term as far... |

49 | Merging monads and folds for functional programming
- Meijer, Jeuring
- 1995
(Show Context)
Citation Context ... a structure after applying its function argument to all elements in the structure. Also known as: ltraversem [11]. Known uses: in unify. Background: Monadic maps (and catamorphisms) are described in =-=[19]-=-. They can be implemented as: pmapM f = thread . pmap f fmapM f g = fthread . fmap f g propagate :: d (Maybe a) -? Maybe (d a) cross :: d [a] -? [d a] Function propagate propagates Nothing to the top ... |

41 | Calculate polytypically
- Meertens
- 1996
(Show Context)
Citation Context ...used in empty leaves.) Known uses: within the library see section 3.5. Many of the functions in that section are then used in the dioeerent applications. Background: The denition of crush is found in =-=[18]-=-. For an associative operator op with unit e, crush op e can be dened as foldr op e . flatten. As crush has the same arguments as fold on lists it can be seen as an alternative to cata as the generali... |

35 |
Homomorphisms and promotability
- Malcolm
- 1989
(Show Context)
Citation Context ...n rewrite. Background: The catamorphism, cata, is the generalisation of the Haskell function foldr and the anamorphism, ana, is the (category theoretic) dual. Catamorphisms were introduced by Malcolm =-=[14, 15]-=-. A hylomorphism is the fused composition of a catamorphism and an anamorphism specied by: hylo i o = cata i . ana o. The paramorphism [17], para, is the elimination rule for the type d a from type th... |

28 | Polytypic pattern matching
- Jeuring
- 1995
(Show Context)
Citation Context ...ave written during the last few years. Most of these are candidates for inclusion in future versions of PolyLib. ffl A polytypic show function and a simple polytypic parser [7]. ffl Pattern matching, =-=[12]-=-, can be dened for all regular datatypes that include an anonymous iwild-cardj. We use a Haskell class HasWildcard with a member function isWild :: t -? Bool to express this restriction. Function pmat... |

27 | Functorial ML
- Bellè, Jay, et al.
- 1996
(Show Context)
Citation Context ...ra, is a generalised form of cata that gives its parameter function access not only to the results of evaluating the substructures, but also the structure itself. Also known as: PolyLib Functorial ML =-=[1]-=- Squiggol charity [3] cata i fold 1 i (jij) ----- i --- ana o - [(o)] (--- o ---) Functions cata and para are instances of the Visitor pattern in [5]. Known uses: Very many polytypic functions are den... |

26 |
Monadic Maps and Folds for Arbitrary Datatypes. Memoranda Informatica 94-28
- Fokkinga
- 1994
(Show Context)
Citation Context ...eneralised in the same way to form even more general 6 combinators. Also known as: traversals [11]. Known uses: in unify and in the parser. Background: Monadic maps and catamorphisms are described in =-=[4]-=-. The monadic map (also called active traversal) is closely related to thread (also called passive traversal): pmapM f = thread . pmap f thread = pmapM id propagate :: d (Maybe a) -? Maybe (d a) cross... |

24 |
Automatic generation and use of abstract structure operators
- Sheard
- 1991
(Show Context)
Citation Context ...the elements pairwise. Known uses: fequal is used in the unication algorithm to determine when two terms are top level equal. Background: An early version of a polytypic equality function appeared in =-=[20]-=-. Function pequal can be instantiated to give a default for the Haskell Eq-class for regular datatypes: (==) :: Eq a =? d a -? d a -? Bool (==) = pequal (==) In Haskell the equality function can be au... |

19 |
Polytypic unification
- Jansson, Jeuring
- 1998
(Show Context)
Citation Context ...tries to match this pattern with the value. ffl Generalizing pattern matching such that it becomes symmetric in its two arguments and allows named wildcards gives unification. The unification program =-=[9]-=-: unify unify :: (Term t,Subst s) =? t -? t -? Maybe (s t) takes two terms and gives Just a unifying substitution if they are unifiable and Nothing otherwise. The member functions of the class Term ca... |

15 | R.: When do datatypes commute
- Hoogendijk, Backhouse
- 1997
(Show Context)
Citation Context ... punzip: it takes a pair of structures and zips them together to Just a structure of pairs if the two structures have the same shape, and to Nothing otherwise. Also known as: zip m [11], zip.\Theta.d =-=[6]-=-, Known uses: Function fzip is used in the denition of pzipWith. Background: The traditional function zip zip :: [a] -? [b] -? [(a,b)] combines two lists and does not need the Maybe type in the result... |

15 |
Analytical and Structural Polymorphism Expressed Using Patterns Over Types
- Ruehr
- 1992
(Show Context)
Citation Context ...ry constructor, but not for all regular types.) A more general (idoubly polytypicj) variant of pzip: transpose (called zip.d.e in [6]) transpose :: d (e a) -? e (d a) was rst described by Fritz Ruehr =-=[19]-=-. For a formal denition, see Hoogendijk & Backhouse [6]. pzipWith :: ((a,b) -? Maybe c) -? (d a,d b) -? Maybe (d (a,b)) pzipWith' :: (FunctorOf d c e -? e) -? ((d a, d b) -? e) -? ((a, b) -? c) -? (d ... |

6 | Genetic algorithms in haskell with polytypic programming
- Vestin
- 1997
(Show Context)
Citation Context ...kes a list of rewrite rules (pairs of terms containing variables) and a term and rewrites the term as far as possible using these rules. ffl A dioeerent application area is that of genetic algorithms =-=[21]-=-, where polytypic functions for doing genetic recombinations of elements of regular datatypes are used. The recombination algorithm uses polytypic functions for extracting or replacing a certain subst... |

5 | The calculation of a polytypic parser
- Huisman
- 1996
(Show Context)
Citation Context ...polytypic applications we have written during the last few years. Most of these are candidates for inclusion in future versions of PolyLib. ffl A polytypic show function and a simple polytypic parser =-=[7]-=-. ffl Pattern matching, [12], can be dened for all regular datatypes that include an anonymous iwild-cardj. We use a Haskell class HasWildcard with a member function isWild :: t -? Bool to express thi... |

5 | Functional polytypic programming | use and implementation - Jansson - 1997 |

1 |
Polytypic unication
- Jansson, Jeuring
- 1998
(Show Context)
Citation Context ...nd tries to match this pattern with the value. ffl Generalising pattern matching such that it becomes symmetric in its two arguments and allows named wild-cards gives unication. The unication program =-=[9]-=-: unify 8 unify :: (Term t,Subst s) =? t -? t -? Maybe (s t) takes two terms and gives Just a unifying substitution if they are uniable and Nothing otherwise. The member functions of the class Term ca... |

1 |
Functorial ML. Extended version of [1
- Jay, Bell, et al.
- 1998
(Show Context)
Citation Context ...he polytypic applications in section 4.) For example: pmap :: (a -? b) -? d a -? d b Function pmap takes a function f and a value x of datatype d a, and applies f . . . Also known as: map [12], map n =-=[11]-=-. Known uses: Everywhere! Background: This was one of the rst . . . A problem with describing a library of polytypic functions is that it is not completely clear how to specify polytypic functions. Th... |

1 |
Functorial ML. Unpublished extended version of [1
- Jay, Bell`e, et al.
- 1997
(Show Context)
Citation Context ...he polytypic applications in section 4.) For example: pmap :: (a -? b) -? d a -? d b Function pmap takes a function f and a value x of datatype d a, and applies f . . . Also known as: map [12], map n =-=[11]-=-. Known uses: Everywhere! Background: This was one of the first . . . A problem with describing a library of polytypic functions is that it is not completely clear how to specify polytypic functions. ... |