EMGM
GenericProgramming
Extensible and Modular Generics for the Masses (
EMGM) applies concepts of datatype-generic programming to define generic
functions for supported datatypes using type classes.
Introduction
Datatype-generic programming
Datatype-generic programming uses a representation of a datatype for defining
generic functions.
EMGM in particular uses a sum-of-products representation,
where a sum represents two alternative constructors and a product represents a
pair of arguments to a constructor.
Generic functions
Generic functions are written for the representation mentioned above along with
a number of primitive types (e.g.
Int,
Double,
Char). Such functions are
generally recursive and written using induction on the elements of the structure
(i.e. unit, sum, and product).
Supported datatypes
Functions in
EMGM are generic, but support for types must be explicitly added.
The library provides representation for many standard datatypes. To add support
for a new datatype, you must write a bit of (usually simple) boilerplate code.
The library code provides good examples to follow.
Type classes
EMGM uses type classes to define generic functions. Each class --
Generic,
Generic2, or
Generic3 -- gives the interface of a function using 1, 2, or 3
generic types. A generic function is then an instance of the appropriate class.
The library also uses type classes as dispatchers for the representation. Rather
than requiring the structure as an argument to a generic function,
EMGM uses
classes to choose the appropriate structure. Thus, all datatypes should be
instances of these dispatcher classes.
Reference
EMGM originated in the research of
Ralf Hinze,
Bruno Oliveira, and
Andres Löh. The library was further explored in a
comparison of generic programming libraries by
Alexey Rodriguez, et al. The current library was developed simultaneously with the writing of (forthcoming)
lecture notes for the
2008 Advanced Functional Programming Summer School.
See the following articles for further reading on the research behind
EMGM. Note that the names of some library elements have changed slightly from those used in the literature, but most of the concepts are still the same.
- Ralf Hinze. Generics for the Masses. In ICFP 2004: Proceedings of the 9th ACM SIGPLAN international conference on Functional programming, pages 236-243. ACM Press, 2004.
- Bruno C. d. S. Oliveira, Ralf Hinze, and Andres Löh. Extensible and Modular Generics for the Masses. In Henrik Nilsson, editor, Trends in Functional Programming, pages 199-216, 2006.
- Alexey Rodriguez, Johan Jeuring, Patrik Jansson, Alex Gerdes, Oleg Kiselyov, and Bruno C. d. S. Oliveira. Comparing Libraries for Generic Programming in Haskell. Technical Report UU-CS-2008-010. Department of Information and Computing Sciences, Utrecht University.
- Johan Jeuring, Sean Leather, José Pedro Magalhães, and Alexey Rodriguez Yakushev. Libraries for Generic Programming in Haskell. Technical Report UU-CS-2008-025. Department of Information and Computing Sciences, Utrecht University.
Releases
We have made several releases of the
EMGM package. Here is some relevant information for each.
emgm-0.3.1
This was the fourth release, made on 05 March 2009.
Changes:
- New functions: deriveMany, deriveManyWith
emgm-0.3
This was the third release, made on 03 March 2009.
Changes:
emgm-0.2
This was the second release, made on 30 January 2009.
Changes:
emgm-0.1
This was the initial release, made on 19 September 2008.
Download
If you have cabal-install, you should use that to install the package,
because it will handle everything for you.
cabal install emgm
If you don't have cabal-install, you must download the
emgm package from
the HackageDB and install it manually. Get the
tar.gz file and decompress it.
Once downloaded, use the following commands for configuring, building, and
installing the library.
runghc Setup.lhs configure
runghc Setup.lhs build
runghc Setup.lhs install
For more details on the general options available, refer to the
Cabal User's Guide.
Source
The source can be checked out from its repository using
Subversion.
svn checkout https://subversion.cs.uu.nl/repos/project.dgp-haskell.libraries/EMGM/trunk
You can also
view the files online.
Bugs & Support
To report bugs, use the Google Code
issue tracker for EMGM.
For general concerns and questions, use the
Generics mailing list.
Development
EMGM has been constantly undergoing development since the idea for releasing the library came about in the
http://www.cs.uu.nl/wiki/Center/? at
http://www.uu.nl/? . It is an open-source project, and we happily welcome discussion (on the
Generics mailing list), suggestions, and/or patches.
To get started, read the
README file that comes with the distribution or in the repository. It describes a number of useful configuration flags and tools that we have used to develop and test
EMGM.