skip to main content
10.1145/1086365.1086391acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
Article

Scrap your boilerplate with class: extensible generic functions

Published:12 September 2005Publication History

ABSTRACT

The '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 cases to be supplied at once, when the recursive knot of generic function definition is tied. Hence, generic functions were closed. In contrast, Haskell's type classes support open, or extensible, functions that can be extended with new type-specific cases as new data types are defined. In this paper, we extend the 'Scrap your boilerplate' approach to support this open style. On the way, we demonstrate the desirability of abstraction over type classes, and the usefulness of recursive dictionarie.

References

  1. Michael Brandt and Fritz Henglein. Coinductive axiomatization of recursive type equality and subtyping. In Proc 3rd International Conference on Typed Lambda Calculi and Appliactions (TLCA'97), Nancy, France, volume 1210 of Lecture Notes in Computer Science, pages 63--81. Springer Verlag, 1997.]] Google ScholarGoogle Scholar
  2. A.I. Baars and S.D. Swierstra. Typing dynamic typing. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2002), pages 157--166. ACM Press, 2002.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. L Cardelli. Amber. In G Cousineau, PL Curien, and B Robinet, editors, Combinators and functional programming languages. LNCS 242, Springer Verlag, 1986.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Koen Claessen and John Hughes. QuickCheck: a lightweight tool for random testing of Haskell programs. In ACM SIGPLAN International Conference on Functional Programming (ICFP'00), pages 268--279, Montreal, September 2000. ACM.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. J. Cheney and R. Hinze. A lightweight implementation of generics and dynamics. In Proceedings of the ACM SIGPLAN Workshop on Haskell, pages 90--104. ACM Press, 2002.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Koen Claessen and John Hughes. Testing monadic code with QuickCheck. In Manuel Chakravarty, editor, Proceedings ofthe 2002 Haskell Workshop, Pittsburgh, October 2002.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Dave Clarke and Andres Löh. Generic Haskell, Specifically. In Proceedings of the IFIP TC2/WG2.1 Working Conference on Generic Programming, pages 21--47. Kluwer, B.V., 2003.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Simon D. Foster. "HAIFA: The Haskell Application Interoperation Framework Architecture"; web site, 2004--2005. http://www.repton-world.org.uk/mediawiki/index.php/HAIFA_Wiki.]]Google ScholarGoogle Scholar
  9. Ralf Hinze. Generics for the masses. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2004), pages 236--243. ACM Press, 2004.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Robert Harper and Greg Morrisett. Compiling polymorphism using intensional type analysis. In Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles Of Programming Languages (POPL 1995), pages 130--141. ACM Press, 1995.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Ralf Hinze and Simon Peyton Jones. Derivable type classes. In Graham Hutton, editor, Proceedings of the 2000 Haskell Workshop, Montreal, number NOTTCS-TR-00-1 in Technical Reports, September 2000.]]Google ScholarGoogle Scholar
  12. RJM Hughes. Restricted data types in haskell. In Erik Meijer, editor, Proceedings of the 1999 Haskell Workshop, number UU-CS-1999-28 in Technical Reports, 1999. ftp://ftp.cs.uu.nl/pub/RUU/CS/techreps/CS-1999/1999-28.pdf.]]Google ScholarGoogle Scholar
  13. Andres Löh, Dave Clarke, and Johan Jeuring. Dependencystyle Generic Haskell. In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2003), pages 141--152. ACM Press, August 25-29 2003.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Jeffrey R. Lewis, John Launchbury, Erik Meijer, and Mark B. Shields. Implicit parameters: dynamic scoping with static types. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles Of Programming Languages (POPL 2000), pages 108--118. ACM Press, 2000.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Ralf Lämmel and Simon Peyton Jones. Scrap your boilerplate: a practical approach to generic programming. In ACM SIGPLAN International Workshop on Types in Language Design and Implementation (TLDI'03), pages 26--37, New Orleans, January 2003. ACM.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Ralf Lämmel and Simon Peyton Jones. Scrap more boilerplate: reflection, zips, and generalised casts. In ACM SIGPLAN International Conference on Functional Programming (ICFP'04), pages 244--255, Snowbird, Utah, September 2004. ACM.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. K Zhuo Ming Lu and M Sulzmann. An implementation of subtyping among regular expression types. In Proc Asian Programming Languages Symposium (APLAS'04), volume 3302 of Lecture Notes in Computer Science, pages 57--73. Springer Verlag, 2004.]]Google ScholarGoogle ScholarCross RefCross Ref
  18. Benjamin Pierce. Types and programming languages. MIT Press, 2002.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. T Sheard and SL Peyton Jones. Template meta-programming for Haskell. In Manuel Chakravarty, editor, Proceedings of the 2002 Haskell Workshop, Pittsburgh, October 2002.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Konstantinos F. Sagonas, Terrance Swift, and David Scott Warren. An abstract machine for efficiently computing queries to well-founded models. J. Log. Program., 45(1--3):1--41, 2000.]]Google ScholarGoogle Scholar
  21. Dimitrios Vytiniotis, Geoffrey Washburn, and Stephanie Weirich. An Open and Shut Typecase. In Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2005). ACM Press, January 2005.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. PL Wadler and S Blott. How to make ad-hoc polymorphism less ad hoc. In Proc 16th ACM Symposium on Principles of Programming Languages, Austin, Texas. ACM, January 1989.]] Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. S. Weirich. Type-safe cast: (functional pearl). In Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2000), pages 58--67. ACM Press, 2000.]] Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Scrap your boilerplate with class: extensible generic functions

        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
        • Published in

          cover image ACM Conferences
          ICFP '05: Proceedings of the tenth ACM SIGPLAN international conference on Functional programming
          September 2005
          342 pages
          ISBN:1595930647
          DOI:10.1145/1086365
          • cover image ACM SIGPLAN Notices
            ACM SIGPLAN Notices  Volume 40, Issue 9
            Proceedings of the tenth ACM SIGPLAN international conference on Functional programming
            September 2005
            330 pages
            ISSN:0362-1340
            EISSN:1558-1160
            DOI:10.1145/1090189
            Issue’s Table of Contents

          Copyright © 2005 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: 12 September 2005

          Permissions

          Request permissions about this article.

          Request Permissions

          Check for updates

          Qualifiers

          • Article

          Acceptance Rates

          Overall Acceptance Rate333of1,064submissions,31%

          Upcoming Conference

          ICFP '24

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader