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 2005 Publication 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.]]
[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.]]
[3]
L Cardelli. Amber. In G Cousineau, PL Curien, and B Robinet, editors, Combinators and functional programming languages. LNCS 242, Springer Verlag, 1986.]]
[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.]]
[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.]]
[6]
Koen Claessen and John Hughes. Testing monadic code with QuickCheck. In Manuel Chakravarty, editor, Proceedings ofthe 2002 Haskell Workshop, Pittsburgh, October 2002.]]
[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.]]
[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.]]
[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.]]
[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.]]
[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.]]
[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.]]
[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.]]
[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.]]
[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.]]
[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.]]
[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.]]
[18]
Benjamin Pierce. Types and programming languages. MIT Press, 2002.]]
[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.]]
[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.]]
[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.]]
[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.]]
[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.]]

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

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
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]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 12 September 2005

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. extensibility
  2. generic programming
  3. recursive dictionaries
  4. type classes
  5. typecase

Qualifiers

  • Article

Conference

ICFP05
Sponsor:

Acceptance Rates

Overall Acceptance Rate 333 of 1,064 submissions, 31%

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)1
  • Downloads (Last 6 weeks)0
Reflects downloads up to 06 Jan 2025

Other Metrics

Citations

Cited By

View all
  • (2024)Tabulation with ZippersFunctional and Logic Programming10.1007/978-981-97-2300-3_5(83-98)Online publication date: 15-May-2024
  • (2019)Coinduction in Uniform: Foundations for Corecursive Proof Search with Horn ClausesProgramming Languages and Systems10.1007/978-3-030-17184-1_28(783-813)Online publication date: 6-Apr-2019
  • (2018)Gradually typed symbolic expressionsProceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation - PEPM '1810.1145/3175493.3162068(15-29)Online publication date: 2018
  • (2018)Type generic observation of intermediate data structures for debugging lazy functional programsComputer Languages, Systems & Structures10.1016/j.cl.2017.05.00152(92-110)Online publication date: Jun-2018
  • (2017)Staging for generic programming in space and timeACM SIGPLAN Notices10.1145/3170492.313606052:12(15-28)Online publication date: 23-Oct-2017
  • (2017)Gradually typed symbolic expressionsProceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation10.1145/3162068(15-29)Online publication date: 25-Dec-2017
  • (2017)Staging for generic programming in space and timeProceedings of the 16th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3136040.3136060(15-28)Online publication date: 23-Oct-2017
  • (2017)Visitors unchainedProceedings of the ACM on Programming Languages10.1145/31102721:ICFP(1-28)Online publication date: 29-Aug-2017
  • (2017)Operational semantics of resolution and productivity in Horn clause logicFormal Aspects of Computing10.1007/s00165-016-0403-129:3(453-474)Online publication date: 1-May-2017
  • (2016)TxRaceACM SIGPLAN Notices10.1145/2954679.287238451:4(159-173)Online publication date: 25-Mar-2016
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media