Abstract
Writing boilerplate code is a royal pain. Generic programming promises to alleviate this pain by allowing the programmer to write a generic "recipe" for boilerplate code, and use that recipe in many places. In earlier work we introduced the "Scrap your boilerplate" approach to generic programming, which exploits Haskell's existing type-class mechanism to support generic transformations and queries.This paper completes the picture. We add a few extra "introspective" or "reflective" facilities, that together support a rich variety of serialisation and de-serialisation. We also show how to perform generic "zips", which at first appear to be somewhat tricky in our framework. Lastly, we generalise the ability to over-ride a generic function with a type-specific one.All of this can be supported in Haskell with independently-useful extensions: higher-rank types and type-safe cast. The GHC implementation of Haskell readily derives the required type classes for user-defined data types.
- T. Altenkirch and C. McBride. Generic programming within dependently typed programming. In Generic Programming, 2003. Proceedings of the IFIP TC2 Working Conference on Generic Programming, Schloss Dagstuhl, July 2002. Google ScholarDigital Library
- F. Atanassow, D. Clarke, and J. Jeuring. UUXML: A Type-Preserving XML Schema-Haskell Data Binding. In B. Jayaraman, editor, Practical Aspects of Declarative Languages: 6th International Symposium, PADL 2004, Dallas, TX, USA, June 18-19, 2004. Proceedings, volume 3057 of LNCS, pages 71--85. Springer-Verlag, May 2004.Google Scholar
- K. Claessen and J. Hughes. QuickCheck: a lightweight tool for random testing of Haskell programs. In ICFP00 {11}, pages 268--279. Google Scholar
- D. Clarke, J. Jeuring, and A. Löh. The Generic Haskell User's Guide, 2002. Version 1.23 - Beryl release.Google Scholar
- D. Clarke and A. Löh. Generic Haskell, Specifically. In J. Gibbons and J. Jeuring, editors, Proc. of the IFIP TC2 Working Conference on Generic Programming. Kluwer Academic Publishers, 2003. Google ScholarDigital Library
- J. Harm and R. Lämmel. Two-dimensional Approximation Coverage. Informatica, 24(3):355--369, 2000.Google Scholar
- R. Hinze. A generic programming extension for Haskell. In Proc. 3rd Haskell Workshop, Paris, France, 1999. Technical report of Universiteit Utrecht, UU-CS-1999-28.Google Scholar
- R. Hinze. Generics for the masses. In these proceedings, 2004. Google ScholarDigital Library
- R. Hughes. A novel representation of lists and its application to the function reverse. Information Processing Letters, 22, 1986. Google ScholarDigital Library
- G. Hutton and E. Meijer. Functional pearl: Monadic parsing in Haskell. Journal of Functional Programming, 8(4):437--444, July 1998. Google ScholarDigital Library
- ACM SIGPLAN International Conference on Functional Programming (ICFP'00), Montreal, Sept. 2000. ACM.Google Scholar
- P. Jansson and J. Jeuring. PolyLib-A library of polytypic functions. In R. Backhouse and T. Sheard, editors, Proc. of Workshop on Generic Programming, WGP'98, Marstrand, Sweden. Dept. of Comp. Science, Chalmers Univ. of Techn. and Göteborg Univ., June 1998.Google Scholar
- C. B. Jay. The pattern calculus. http://www-staff.it.uts.edu.au/~cbj/Publications/pattern_calculus.ps, 2003. (accepted for publication by ACM TOPLAS.). Google ScholarDigital Library
- P. W. M. Koopman, A. Alimarine, J. Tretmans, and M. J. Plasmeijer. Gast: Generic Automated Software Testing. In R. Pena and T. Arts, editors, Implementation of Functional Languages, 14th International Workshop, IFL 2002, Madrid, Spain, September 16-18, 2002, Revised Selected Papers, volume 2670 of LNCS, pages 84--100. Springer-Verlag, 2003. Google ScholarDigital Library
- R. Lämmel and J. Harm. Test case characterisation by regular path expressions. In E. Brinksma and J. Tretmans, editors, Proc. Formal Approaches to Testing of Software (FATES'01), Notes Series NS-01-4, pages 109--124. BRICS, Aug. 2001.Google Scholar
- R. Lämmel and S. Peyton Jones. Scrap your boilerplate: a practical design pattern for generic programming. ACM SIGPLAN Notices, 38(3):26--37, Mar. 2003. Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2003). Google ScholarDigital Library
- The "Scrap your boilerplate" web site: examples, browsable library, papers, background, 2003-2004. http://www.cs.vu.nl/boilerplate/.Google Scholar
- D. Lelewer and D. Hirschberg. Data compression. ACM Computing Surveys, 19(3):261--296, Sept. 1987. Google ScholarDigital Library
- A. Löh, D. Clarke, and J. Jeuring. Dependency-style Generic Haskell. In C. Norris and J. J. B. Fenwick, editors, Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming (ICFP-03), volume 38, 9 of ACM SIGPLAN Notices, pages 141--152, New York, Aug. 25-29 2003. ACM Press. Google ScholarDigital Library
- S. Peyton Jones and M. Shields. Practical type inference for higher-rank types. Unpublished manuscript, 2004.Google Scholar
- M. Wallace and C. Runciman. Haskell and XML: Generic combinators or type-based translation. In ACM SIGPLAN International Conference on Functional Programming (ICFP'99), pages 148--159, Paris, Sept. 1999. ACM. Google ScholarDigital Library
- S. Weirich. Type-safe cast. In ICFP00 {11}, pages 58--67. Google Scholar
- I. Witten, R. Neal, and J. Cleary. Arithmetic coding for data compression. CACM, 30(6):520--540, June 1987. Google ScholarDigital Library
Index Terms
- Scrap more boilerplate: reflection, zips, and generalised casts
Recommendations
Scrap more boilerplate: reflection, zips, and generalised casts
ICFP '04: Proceedings of the ninth ACM SIGPLAN international conference on Functional programmingWriting boilerplate code is a royal pain. Generic programming promises to alleviate this pain by allowing the programmer to write a generic "recipe" for boilerplate code, and use that recipe in many places. In earlier work we introduced the "Scrap your ...
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 ...
Scrap your boilerplate: a practical design pattern for generic programming
We describe a design pattern for writing programs that traverse data structures built from rich mutually-recursive data types. Such programs often have a great deal of "boilerplate" code that simply walks the structure, hiding a small amount of "real" ...
Comments