Institute of Information and Computing Sciences Utrecht University P.O. Box 80.

Institute of Information and Computing Sciences Utrecht University P.O. Box 80.089 3508 TB Utrecht The Netherlands http://www.generic-haskell.org The Generic H A SKELL User’s Guide The Generic H A SKELL Team Dæv Clarke Ralf Hinze Johan Jeuring Andres L¨ oh Jan de Wit info@generic-haskell.org November 1, 2001 Version 0.99 (Amber) Contents 1 What is Generic H A SKELL? 4 1.1 Generic Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2 Generic H A SKELL overview . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 Installation 5 2.1 System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2 Installing the binary distribution . . . . . . . . . . . . . . . . . . . . . . . 5 2.3 Building from source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.4 Running gh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.5 Compiling and running the generated code . . . . . . . . . . . . . . . . . 6 3 Generic H A SKELL: The Language 7 3.1 Special Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Kind-indexed types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.3 Type-indexed values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 Generic application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.5 Generic abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.6 Type-indexed types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.7 Generated function naming . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.8 Haskell compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4 Library 12 4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.2 Module Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.3 Module Collect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.4 Module Compare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.5 Module Eq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.6 Module Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.7 Module MapM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.8 Module ReadShow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.9 Module Reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.10 Module Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.11 Module ZipWith . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5 Future Work 16 2 6 Meta-information 17 6.1 Contact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 6.2 Caveats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 6.3 Known bugs and limitations . . . . . . . . . . . . . . . . . . . . . . . . . . 17 6.4 Change Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 6.5 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 6.6 Copyright information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3 1 What is Generic H A SKELL? 1.1 Generic Programming Software development often consists of designing datatypes around which functionality is added. Some functionality is datatype specific, whereas other functionality is defined on almost all datatypes in such a way that it depends only on the structure of the datatype. A function that works on many datatypes in this way is called a generic (or polytypic) function. Examples of generic functionality include storing a value in a database, editing a value, comparing two values for equality, pretty-printing a value. Since datatypes often change and new datatypes are introduced, we have developed Generic H A SKELL, an extension of the functional programming language Haskell [5] that supports generic definitions, to save the programmer from (re)writing instances of generic functions. Generic H A SKELL extends Haskell with, among other things, a construct for defining type-indexed values with kind-indexed types, based on recent work by Hinze [2]. These values can be specialised to all Haskell datatypes, facilitating wider application of generic programming than provided by earlier systems such as PolyP [4]. 1.2 Generic H A SKELL overview Generic H A SKELL extends Haskell with a number of features. • type-indexed values are defined as a value indexed over the various Haskell type constructors (unit, primitive types, sums, products, and user-defined type con- structors). The resulting type-indexed value can be specialised to any type. • kind-indexed types are types indexed over kinds, defined by giving a case for both ∗and κ →κ′. Instances are obtained by applying the kind-indexed type to a kind. • generic definitions can be used by applying them to a type or kind. This is called generic application. The result is a type or value, depending on which sort uploads/s3/ ghusers-guide.pdf

  • 29
  • 0
  • 0
Afficher les détails des licences
Licence et utilisation
Gratuit pour un usage personnel Attribution requise
Partager