skip to main content
article

Scrap more boilerplate: reflection, zips, and generalised casts

Published:19 September 2004Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle Scholar
  3. K. Claessen and J. Hughes. QuickCheck: a lightweight tool for random testing of Haskell programs. In ICFP00 {11}, pages 268--279. Google ScholarGoogle Scholar
  4. D. Clarke, J. Jeuring, and A. Löh. The Generic Haskell User's Guide, 2002. Version 1.23 - Beryl release.Google ScholarGoogle Scholar
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. J. Harm and R. Lämmel. Two-dimensional Approximation Coverage. Informatica, 24(3):355--369, 2000.Google ScholarGoogle Scholar
  7. 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 ScholarGoogle Scholar
  8. R. Hinze. Generics for the masses. In these proceedings, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. R. Hughes. A novel representation of lists and its application to the function reverse. Information Processing Letters, 22, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. G. Hutton and E. Meijer. Functional pearl: Monadic parsing in Haskell. Journal of Functional Programming, 8(4):437--444, July 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. ACM SIGPLAN International Conference on Functional Programming (ICFP'00), Montreal, Sept. 2000. ACM.Google ScholarGoogle Scholar
  12. 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 ScholarGoogle Scholar
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle Scholar
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. The "Scrap your boilerplate" web site: examples, browsable library, papers, background, 2003-2004. http://www.cs.vu.nl/boilerplate/.Google ScholarGoogle Scholar
  18. D. Lelewer and D. Hirschberg. Data compression. ACM Computing Surveys, 19(3):261--296, Sept. 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. S. Peyton Jones and M. Shields. Practical type inference for higher-rank types. Unpublished manuscript, 2004.Google ScholarGoogle Scholar
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. S. Weirich. Type-safe cast. In ICFP00 {11}, pages 58--67. Google ScholarGoogle Scholar
  23. I. Witten, R. Neal, and J. Cleary. Arithmetic coding for data compression. CACM, 30(6):520--540, June 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Scrap more boilerplate: reflection, zips, and generalised casts

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image ACM SIGPLAN Notices
              ACM SIGPLAN Notices  Volume 39, Issue 9
              ICFP '04
              September 2004
              254 pages
              ISSN:0362-1340
              EISSN:1558-1160
              DOI:10.1145/1016848
              Issue’s Table of Contents
              • cover image ACM Conferences
                ICFP '04: Proceedings of the ninth ACM SIGPLAN international conference on Functional programming
                September 2004
                264 pages
                ISBN:1581139055
                DOI:10.1145/1016850

              Copyright © 2004 ACM

              Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 19 September 2004

              Check for updates

              Qualifiers

              • article

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader