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

RepLib: a library for derivable type classes

Published: 17 September 2006 Publication History

Abstract

Some type class instances can be automatically derived from the structure of types. As a result, the Haskell language includes the "deriving" mechanism to automatic generates such instances for a small number of built-in type classes. In this paper, we present RepLib, a GHC library that enables a similar mechanism for arbitrary type classes. Users of RepLib can define the relationship between the structure of a datatype and the associated instance declaration by a normal Haskell functions that pattern-matches a representation type. Furthermore, operations defined in this manner are extensible-instances for specific types not defined by type structure may also be incorporated. Finally, this library also supports the definition of operations defined by parameterized types.

References

[1]
Martín Abadi, Luca Cardelli, Benjamin Pierce, and Gordon Plotkin. Dynamic typing in a statically-typed language. ACM Transactions on Programming Languages and Systems, 13(2):237--268, April 1991.]]
[2]
James Cheney and Ralf Hinze. First-class phantom types. CUCIS TR2003-1901, Cornell University, 2003.]]
[3]
Dave Clarke, Ralf Hinze, Johan Jeuring, Andres Löh, and Jan de Wit. The Generic Haskell user's guide. Technical Report UU-CS-2001-26, Utrecht University, 2001.]]
[4]
Karl Crary, Stephanie Weirich, and Greg Morrisett. Intensional polymorphism in type erasure semantics. Journal of Functional Programming, 12(6):567--600, November 2002.]]
[5]
Bruno C. d. S. Oliveira and Jeremy Gibbons. TypeCase: A design pattern for type-indexed functions. In Haskell Workshop, Tallinn, Estonia, 2005.]]
[6]
DrIFT User Manual, April 2006. Available at http://repetae.net/~john/computer/haskell/DrIFT/.]]
[7]
The GHC Team. The Glasgow Haskell Compiler User's Guide, version 5.02 edition, 2002. Available at http://www.haskell.org/ghc/.]]
[8]
Cordelia V. Hall, Kevin Hammond, Simon L. Peyton Jones, and Philip L. Wadler. Type classes in Haskell. ACM Transactions on Programming Languages and Systems, 18(2):109--138, March 1996.]]
[9]
Ralf Hinze. Polytypic values possess polykinded types. In Roland Backhouse and J.N. Oliveira, editors, Proceedings of the Fifth International Conference on Mathematics of Program Construction (MPC 2000), pages 2--27, Ponte de Lima, Portugal, July 2000.]]
[10]
Ralf Hinze. Generics for the masses. In International Conference on Functional Programming (ICFP), pages 236--243, September 2004.]]
[11]
Ralf Hinze and Simon Peyton Jones. Derivable type classes. In Graham Hutton, editor, Proceedings of the Fourth Haskell Workshop, Montreal, Canada, September 17, 2000, volume 41.1 of Electronic Notes in Theoretical Computer Science. Elsevier Science, August 2000.]]
[12]
Ralf Hinze and Andres Löh. Scrap Your Boilerplate revolutions. In 8th International Conference on Mathematics of Program Construction, MPC 2006, Kuressaare, Estonia, July 2006.]]
[13]
Ralf Hinze, Andres Löh, and Bruno C. d. S. Oliveira. Scrap Your Boilerplate reloaded. In Eighth International Symposium on Functional and Logic Programming, FLOPS 2006, April 2005.]]
[14]
Ralf Hinze, Andres Löh, and Bruno C. d. S. Oliveira. Scrap Your Boilerplate reloaded (extended version). Technical report, 2005. Available at http://www.informatik.uni-bonn.de/~loeh/SYB0-TR.pdf.]]
[15]
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.]]
[16]
Stefan Holdermans, Johan Jeuring, Andres Löh, and Alexey Rodriguez. Generic views on data types. In 8th International Conference on Mathematics of Program Construction, MPC 2006, Kuressaare, Estonia, July 2006.]]
[17]
John Hughes. Restricted datatypes in Haskell. In Haskell Workshop, number UU-CS-1999-28, 1999.]]
[18]
Patrick Jansson and Johan Jeuring. PolyP-A polytypic programming language extension. In Twenty-Fourth ACMSIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 470--482, Paris, France, 1997.]]
[19]
Wolfram Kahl and Jan Scheffczyk. Named instances for haskell type classes. In Haskell Workshop 2001, Firenze, Italy, September 2001.]]
[20]
Oleg Kiselyov, Ralf Lämmel, and Keean Schupke. Strongly typed heterogeneous collections. In Haskell '04: Proceedings of the ACM SIGPLAN workshop on Haskell, pages 96--107, 2004.]]
[21]
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 Press.]]
[22]
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.]]
[23]
Ralf Lämmel and Simon Peyton Jones. Scrap your boilerplate with class: Extensible generic functions. In ACM SIGPLAN International Conference on Functional Programming (ICFP'05), Tallin, Estonia, 2005.]]
[24]
Andres Löh, Dave Clarke, and Johan Juering. Dependency-style Generic Haskell. In ACM SIGPLAN International Conference on Functional Programming (ICFP), Uppsala, Sweden, 2003. To appear.]]
[25]
Erik Meijer and Graham Hutton. Bananas in space: Extending fold and unfold to exponential types. In FPCA95: Conference on Functional Programming Languages and Computer Architecture (FPLCA), pages 324--333, La Jolla, CA, June 1995.]]
[26]
Martin Odersky and Konstantin Läufer. Putting type annotations to work. In Conference Record of POPL '96: The 23rd ACM SIGPLANSIGACT Symposium on Principles of Programming Languages, St. Petersberg Beach, Florida, pages 54--67, New York, N.Y., 1996.]]
[27]
Bruno C.d.S. Oliveira, Ralf Hinze, and Andres Löh. Generics as a library. In Seventh Symposium on Trends in Functional Programming, TFP 2006, Nottingham, UK, April 2006.]]
[28]
Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. Simple unification-based type inference for GADTs. In International Conference on Functional Programming (ICFP), Portland, OR, USA, September 2006.]]
[29]
Simon L. Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. Practical type inference for arbitrary-rank types. Journal of Functional Programming, 2006. To appear.]]
[30]
T Sheard and SL Peyton Jones. Template meta-programming for Haskell. In Manuel Chakravarty, editor, Proceedings of the 2002 Haskell Workshop, Pittsburgh, October 2002.]]
[31]
Mark Shields and Simon Peyton Jones. Lexically scoped type variables. Microsoft Research, 2002.]]
[32]
Philip Wadler and Stephen Blott. How to make ad-hoc polymorphism less ad hoc. In Sixteenth ACMSIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 60--76. ACM Press, 1989.]]
[33]
Geoffrey Washburn and Stephanie Weirich. Good advice for typedirected programming: Aspect-oriented programming and extensible generic functions. In Workshop on Generic Programming (WGP), Portland, OR, USA, September 2006.]]
[34]
Stephanie Weirich. Encoding intensional type analysis. In D. Sands, editor, 10th European Symposium on Programming (ESOP), pages 92--106, Genova, Italy, April 2001.]]
[35]
Stephanie Weirich. Higher-order intensional type analysis. In Daniel Le Mßtayer, editor, 11th European Symposium on Programming (ESOP), pages 98--114, Grenoble, France, April 2002.]]
[36]
Stephanie Weirich. Programming With Types. PhD thesis, Cornell University, August 2002.]]
[37]
Stephanie Weirich. Higher-order intensional type analysis in type erasure semantics, July 2003. At http://www.cis.upenn.edu/ ~sweirich/papers/erasure/erasure-paper-july03.pdf.]]
[38]
Stephanie Weirich. Type-safe cast. Journal of Functional Programming, 14(6):681--695, November 2004.]]
[39]
Stephanie Weirich. Type-safe run-time polytypic programming. Journal of Functional Programming, 2006. To appear.]]

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
Haskell '06: Proceedings of the 2006 ACM SIGPLAN workshop on Haskell
September 2006
131 pages
ISBN:1595934898
DOI:10.1145/1159842
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: 17 September 2006

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. GADT
  2. datatype-generic programming
  3. representation types
  4. type-indexed programming

Qualifiers

  • Article

Conference

ICFP06
Sponsor:

Acceptance Rates

Overall Acceptance Rate 57 of 143 submissions, 40%

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)3
  • Downloads (Last 6 weeks)0
Reflects downloads up to 19 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (2018)Generic Programming in OCamlElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.285.3285(59-100)Online publication date: 31-Dec-2018
  • (2017)Visitors unchainedProceedings of the ACM on Programming Languages10.1145/31102721:ICFP(1-28)Online publication date: 29-Aug-2017
  • (2017)Hazelnut: a bidirectionally typed structure editor calculusACM SIGPLAN Notices10.1145/3093333.300990052:1(86-99)Online publication date: 1-Jan-2017
  • (2017)Java generics are turing completeACM SIGPLAN Notices10.1145/3093333.300987152:1(73-85)Online publication date: 1-Jan-2017
  • (2017)Java generics are turing completeProceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages10.1145/3009837.3009871(73-85)Online publication date: 1-Jan-2017
  • (2016)A Reflection on TypesA List of Successes That Can Change the World10.1007/978-3-319-30936-1_16(292-317)Online publication date: 25-Mar-2016
  • (2015)Datatype generic programming in F#Proceedings of the 11th ACM SIGPLAN Workshop on Generic Programming10.1145/2808098.2808101(23-32)Online publication date: 30-Aug-2015
  • (2014)True sums of productsProceedings of the 10th ACM SIGPLAN workshop on Generic programming10.1145/2633628.2633634(83-94)Online publication date: 26-Aug-2014
  • (2013)Usage of generic programming on hackageProceedings of the 9th ACM SIGPLAN workshop on Generic programming10.1145/2502488.2502494(47-52)Online publication date: 28-Sep-2013
  • (2011)Binders unboundProceedings of the 16th ACM SIGPLAN international conference on Functional programming10.1145/2034773.2034818(333-345)Online publication date: 19-Sep-2011
  • 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

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media