### – Generic programming at Utrecht –

, 2009

"... Generic programs are programs that abstract over types. Generic programs can be used to address several common programming patterns. This paper discusses why generic programming is useful, gives applications of generic programming, and discusses the history of generic programming and current generic ..."

Abstract
- Add to MetaCart

Generic programs are programs that abstract over types. Generic programs can be used to address several common programming patterns. This paper discusses why generic programming is useful, gives applications of generic programming, and discusses the history of generic programming and current generic programming activities at Utrecht University. Constructing software.

### Termination Combinators Forever

"... We describe a library-based approach to constructing termination tests suitable for controlling termination of symbolic methods such as partial evaluation, supercompilation and theorem proving. With our combinators, all termination tests are correct by construction. We show how the library can be de ..."

Abstract
- Add to MetaCart

We describe a library-based approach to constructing termination tests suitable for controlling termination of symbolic methods such as partial evaluation, supercompilation and theorem proving. With our combinators, all termination tests are correct by construction. We show how the library can be designed to embody various optimisations of the termination tests, which the user of the library takes advantage of entirely transparently. Categories and Subject Descriptors D.3.2 [Programming Languages]: Language Classifications – Applicative (functional) languages

### Under consideration for publication in J. Functional Programming 1 Comparing Datatype-Generic Libraries

, 924

"... Datatype-generic programming is parametrizing programs by the structure, or “shape ” of datatypes, letting us write, for example, generic traversal or pretty-printing once and apply them to any data type whose shape we can represent. Although more than two decades old, the field has been vigorously ..."

Abstract
- Add to MetaCart

Datatype-generic programming is parametrizing programs by the structure, or “shape ” of datatypes, letting us write, for example, generic traversal or pretty-printing once and apply them to any data type whose shape we can represent. Although more than two decades old, the field has been vigorously growing in recent years, particularly in Haskell. There are more than ten datatype-generic programming libraries in Haskell, not counting proposed language extensions. The proliferation of the libraries poses the problem of comparing them, to help the users choose the right library for their tasks and to attempt to unify some of them. In this paper we develop an extensive test suite for comparing datatype-generic libraries in a typed functional language. We introduce a broad set of criteria and develop a collection of characteristic examples covering most of the facets of datatype-generic programming. We have implemented the examples for ten existing Haskell generic programming libraries and report for the first time the comprehensive evaluation of the libraries against the broad common standard. ZU064-05-FPR ComparingJournal 21 June 2011 16:28 2 Rodriguez Yakushev et al. 1

### Evaluation: Exp → Value

"... We have a number of domain-specific languages. Each pair shares some common sublanguage. All of them share a common language of values. We have the same situation on the type level! How do we implement this system without duplicating code?! ..."

Abstract
- Add to MetaCart

We have a number of domain-specific languages. Each pair shares some common sublanguage. All of them share a common language of values. We have the same situation on the type level! How do we implement this system without duplicating code?!

### Domain-Specific Languages in POETS

"... We have a number of domain-specific languages. Each pair shares some common sublanguage. All of them share a common language of values. We have the same situation on the type level! How do we implement this system without duplicating code! 4 How Can we Compose Data Structures?... and Functions Defin ..."

Abstract
- Add to MetaCart

We have a number of domain-specific languages. Each pair shares some common sublanguage. All of them share a common language of values. We have the same situation on the type level! How do we implement this system without duplicating code! 4 How Can we Compose Data Structures?... and Functions Defined on Them? This is easy on non-recursive data structures. Composition by sum or product. For recursively defined data structures this is different. Example (A simple expression language) data Expr = Val Int

### General Terms

"... Building on Wouter Swierstra’s Data types à la carte, we present a comprehensive Haskell library of compositional data types suitable for practical applications. In this framework, data types and functions on them can be defined in a modular fashion. We extend the existing work by implementing a wid ..."

Abstract
- Add to MetaCart

Building on Wouter Swierstra’s Data types à la carte, we present a comprehensive Haskell library of compositional data types suitable for practical applications. In this framework, data types and functions on them can be defined in a modular fashion. We extend the existing work by implementing a wide array of recursion schemes including monadic computations. Above all, we generalise recursive data types to contexts, which allow us to characterise a special yet frequent kind of catamorphisms. The thus established notion of term homomorphisms allows for flexible reuse and enables shortcut fusion style deforestation which yields considerable speedups. We demonstrate our framework in the setting of compiler construction, and moreover, we compare compositional data types with generic programming techniques and show that both are comparable in run-time performance and expressivity while our approach allows for stricter types. We substantiate this conclusion by lifting compositional data types to mutually recursive data types and generalised algebraic data types. Lastly, we compare the run-time performance of our techniques with traditional implementations over algebraic data types. The results are surprisingly good.

### Modular Tree Automata

"... Abstract. Tree automata are traditionally used to study properties of tree languages and tree transformations. In this paper, we consider tree automata as the basis for modular and extensible recursion schemes. We show, using well-known techniques, how to derive from standard tree automata highly mo ..."

Abstract
- Add to MetaCart

Abstract. Tree automata are traditionally used to study properties of tree languages and tree transformations. In this paper, we consider tree automata as the basis for modular and extensible recursion schemes. We show, using well-known techniques, how to derive from standard tree automata highly modular recursion schemes. Functions that are defined in terms of these recursion schemes can be combined, reused and transformed in many ways. This flexibility facilitates the specification of complex transformations in a concise manner, which is illustrated with a number of examples. 1

### General Terms

"... Much has been said and done about generic programming approaches in strongly-typed functional languages such as Haskell and Agda. Different approaches use different techniques and are better or worse suited for certain uses, depending on design decisions such as generic view, universe size and compl ..."

Abstract
- Add to MetaCart

Much has been said and done about generic programming approaches in strongly-typed functional languages such as Haskell and Agda. Different approaches use different techniques and are better or worse suited for certain uses, depending on design decisions such as generic view, universe size and complexity, etc. We present a simple and intuitive yet powerful approach to generic programming in Agda using indexed functors. We show a universe incorporating fixed points that supports composition, indexing, and isomorphisms, and generalizes a number of previous approaches to generic programming with fixed points. Our indexed functors come with a map operation which obeys the functor laws, and associated recursion morphisms. Albeit expressive, the universe remains simple enough to allow defining standard recursion schemes as well as decidable equality. As for type-indexed datatypes, we show how to compute the type of one-hole contexts and define the generic zipper.

### niques]: Functional Programming General Terms

"... An indexed datatype is a type that uses a parameter as a type-level tag; a typical example is the type of vectors, which are indexed over a type-level natural number encoding their length. Since the introduction of generalised algebraic datatypes, indexed datatypes have become commonplace in Haskell ..."

Abstract
- Add to MetaCart

An indexed datatype is a type that uses a parameter as a type-level tag; a typical example is the type of vectors, which are indexed over a type-level natural number encoding their length. Since the introduction of generalised algebraic datatypes, indexed datatypes have become commonplace in Haskell. Values of indexed datatypes are often more involved than values of plain datatypes, and programmers would benefit from having generic programs on indexed datatypes. However, no generic programming library adequately supports them, leaving programmers with the tedious task of writing repetitive code. We show how to encode indexed datatypes in a generic programming library with type families and type-level representations in Haskell. Our approach can also be used in similar libraries, and is fully backwards-compatible. We show not only how to encode indexed datatypes generically, but also how to instantiate generic functions on indexed datatypes. Furthermore, all generic representations and instances are generated automatically, making life easier for users.