Abstract
A generic function is a function that can be instantiated on many data types to obtain data type specific functionality. Examples of generic functions are the functions that can be derived in Haskell, such as show, read, and '=='. The recent years have seen a number of proposals that support the definition of generic functions. Some of the proposals define new languages, some define extensions to existing languages. As a common characteristic none of the proposals can be made to work within Haskell 98: they all require something extra, either a more sophisticated type system or an additional language construct. The purpose of this pearl is to show that one can, in fact, program generically within Haskell 98 obviating to some extent the need for fancy type systems or separate tools. Haskell's type classes are at the heart of this approach: they ensure that generic functions can be defined succinctly and, in particular, that they can be used painlessly.
- Roland Backhouse, Patrik Jansson, Johan Jeuring, and Lambert Meertens. Generic Programming --- An Introduction ---. In S. Doaitse Swierstra, Pedro R. Henriques, and Jose N. Oliveira, editors, 3rd International Summer School on Advanced Functional Programming, Braga, Portugal, volume 1608 of Lecture Notes in Computer Science, pages 28--115. Springer-Verlag, Berlin, 1999.Google Scholar
- James Cheney and Ralf Hinze. A lightweight implementation of generics and dynamics. In Manuel M.T. Chakravarty, editor, Proceedings of the 2002 ACM SIGPLAN Haskell Workshop, pages 90--104. ACM Press, October 2002. Google ScholarDigital Library
- Ralf Hinze. A new approach to generic functional programming. In Thomas W. Reps, editor, Proceedings of the 27th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'00), Boston, Massachusetts, January 19-21, pages 119--132, January 2000. Google ScholarDigital Library
- Ralf Hinze. Polytypic values possess polykinded types. Science of Computer Programming, 43:129--159, 2002.Google ScholarCross Ref
- Ralf Hinze. Fun with phantom types. In Jeremy Gibbons and Oege de Moor, editors, The Fun of Programming, pages 245--262. Palgrave Macmillan, 2003. ISBN 1-4039-0772-2 hardback, ISBN 0-333-99285-7 paperback.Google ScholarCross Ref
- Ralf Hinze and Johan Jeuring. Generic Haskell: Applications. In Roland Backhouse and Jeremy Gibbons, editors, Generic Programming: Advanced Lectures, volume 2793 of Lecture Notes in Computer Science. Springer-Verlag, 2003.Google Scholar
- Ralf Hinze and Johan Jeuring. Generic Haskell: Practice and theory. In Roland Backhouse and Jeremy Gibbons, editors, Generic Programming: Advanced Lectures, volume 2793 of Lecture Notes in Computer Science. Springer-Verlag, 2003.Google Scholar
- Ralf Hinze, Johan Jeuring, and Andres Löh. Type-indexed data types. Science of Computer Programming, 51:117--151, 2004. Google ScholarDigital Library
- Patrik Jansson and Johan Jeuring. PolyP---a polytypic programming language extension. In Conference Record 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL'97), Paris, France, pages 470--482. ACM Press, January 1997. Google ScholarDigital Library
- Ralf Lämmel and Simon Peyton Jones. Scrap more boilerplate: reflection, zips, and generalised casts. In Kathleen Fisher, editor, Proceedings of the 2004 International Conference on Functional Programming, Snowbird, Utah, September 19--22, 2004, September 2004. Google ScholarDigital Library
- Simon Peyton Jones. Haskell 98 Language and Libraries. Cambridge University Press, 2003.Google Scholar
- Simon Peyton Jones and Ralf Lämmel. Scrap your boilerplate: a practical approach to generic programming. In Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2003), New Orleans, January 2003. Google ScholarDigital Library
- Philip Wadler. A prettier printer. In Jeremy Gibbons and Oege de Moor, editors, The Fun of Programming, Cornerstones of Computing, pages 223--243. Palgrave Macmillan Publishers Ltd, March 2003.Google Scholar
- Stephanie Weirich. Higher-order intensional type analysis in type-erasure semantics. Available from http://www.cis.upenn.edu/~sweirich/papers/erasure/erasure-paper-july03.pdf, 2003.Google Scholar
Index Terms
- Generics for the masses
Recommendations
Generics for the masses
ICFP '04: Proceedings of the ninth ACM SIGPLAN international conference on Functional programmingA generic function is a function that can be instantiated on many data types to obtain data type specific functionality. Examples of generic functions are the functions that can be derived in Haskell, such as show, read, and '=='. The recent years have ...
Generic programming in 3D
Support for generic programming consists of three essential ingredients: support for overloaded functions, a run-time type representation, and a generic view on data. Different approaches to datatype-generic programming occupy different points in this ...
Scrap your boilerplate with class: extensible generic functions
Proceedings of the tenth ACM SIGPLAN international conference on Functional programmingThe 'Scrap your boilerplate' approach to generic programming allows the programmer to write generic functions that can traverse arbitrary data structures, and yet have type-specific cases. However, the original approach required all the type-specific ...
Comments