skip to main content
research-article

A generic deriving mechanism for Haskell

Published:30 September 2010Publication History
Skip Abstract Section

Abstract

Haskell's deriving mechanism supports the automatic generation of instances for a number of functions. The Haskell 98 Report only specifies how to generate instances for the Eq, Ord, Enum, Bounded, Show, and Read classes. The description of how to generate instances is largely informal. The generation of instances imposes restrictions on the shape of datatypes, depending on the particular class to derive. As a consequence, the portability of instances across different compilers is not guaranteed.

We propose a new approach to Haskell's deriving mechanism, which allows users to specify how to derive arbitrary class instances using standard datatype-generic programming techniques. Generic functions, including the methods from six standard Haskell 98 derivable classes, can be specified entirely within Haskell 98 plus multi-parameter type classes, making them lightweight and portable. We can also express Functor, Typeable, and many other derivable classes with our technique. We implemented our deriving mechanism together with many new derivable classes in the Utrecht Haskell Compiler.

Skip Supplemental Material Section

Supplemental Material

haskell-1055-magalhaes.mov

References

  1. }}Artem Alimarine and Rinus Plasmeijer. A Generic Programming Extension for Clean. In IFL'01, pages 168--185. Springer-Verlag, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. }}Roland Backhouse, Patrik Jansson, Johan Jeuring, and Lambert Meertens. Generic programming - an introduction. In AFP'98, volume 1608 of LNCS, pages 28--115. Springer, 1999.Google ScholarGoogle Scholar
  3. }}Manuel M. T. Chakravarty, Gabriel C. Ditu, and Roman Leshchinskiy. Instant generics: Fast and easy, 2009. Draft version.Google ScholarGoogle Scholar
  4. }}Atze Dijkstra, Jeroen Fokker, and S. Doaitse Swierstra. The architecture of the Utrecht Haskell compiler. In Haskell'09, pages 93--104. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. }}Erik Hesselink. Generic programming with fixed points for parametrized datatypes. Master's thesis, Utrecht University, 2009.Google ScholarGoogle Scholar
  6. }}Ralf Hinze. Polytypic values possess polykinded types. SCP, 43(2-3):129--159, 2002.Google ScholarGoogle Scholar
  7. }}Ralf Hinze and Andres Löh. Generic programming in 3D. SCP, 74(8): 590--628, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. }}Ralf Hinze and Simon Peyton Jones. Derivable type classes. Electronic Notes in Theoretical Computer Science, 41(1):5--35, 2001.Google ScholarGoogle ScholarCross RefCross Ref
  9. }}Ralf Hinze, Johan Jeuring, and Andres Löh. Type-indexed data types. In MPC'02, volume 2386 of LNCS, pages 148--174. Springer, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. }}Ralf Hinze, Johan Jeuring, and Andres Löh. Comparing approches to generic programming in Haskell. In Datatype-Generic Programming, volume 4719 of LNCS, pages 72--149. Springer, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. }}Gérard Huet. The zipper. JFP, 7(5):549--554, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. }}Patrik Jansson and Johan Jeuring. PolyP - a polytypic programming language extension. In POPL'97, pages 470--482. ACM, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. }}Mark Jones. Type classes with functional dependencies. In ESOP'00, volume 1782 of LNCS, pages 230--244. Springer, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. }}Ralf Lämmel and Simon Peyton Jones. Scrap your boilerplate: a practical approach to generic programming. In TLDI'03, pages 26--37, 2003.Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. }}Ralf Lämmel and Simon Peyton Jones. Scrap more boilerplate: reflection, zips, and generalised casts. In ICFP'04, pages 244--255. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. }}Andres Löh. Exploring Generic Haskell. PhD thesis, Utrecht University, 2004.Google ScholarGoogle Scholar
  17. }}José Pedro Magalhães, Stefan Holdermans, Johan Jeuring, and Andres Löh. Optimizing generics is easy! In PEPM'10, pages 33--42. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. }}Thomas van Noort, Alexey Rodriguez Yakushev, Stefan Holdermans, Johan Jeuring, and Bastiaan Heeren. A lightweight approach to datatypegeneric rewriting. In WGP'08, pages 13--24. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. }}Bruno C. d. S. Oliveira, Ralf Hinze, and Andres Löh. Extensible and modular Bruno C. d. S. Oliveira, Ralf Hinze, and Andres Löh. Extensible and modular generics for the masses. In TFP'06, pages 199--216. Intellect, 2007.Google ScholarGoogle Scholar
  20. }}Simon Peyton Jones et al. Haskell 98, Language and Libraries. The Revised Report. Cambridge University Press, 2003. A special issue of JFP.Google ScholarGoogle Scholar
  21. }}Alexey Rodriguez Yakushev, Johan Jeuring, Patrik Jansson, Alex Gerdes, Oleg Kiselyov, and Bruno C. d. S. Oliveira. Comparing libraries for generic programming in Haskell. In Haskell'08, pages 111--122. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. }}Tom Schrijvers, Simon Peyton Jones, Manuel M. T. Chakravarty, and Martin Sulzmann. Type checking with open type functions. In ICFP'08, pages 51--62. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. }}Tim Sheard and Simon Peyton Jones. Template metaprogramming for Haskell. In Haskell'02, pages 1--16. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. }}Malcom Wallace et al. Derived instances - Haskell Prime. http://hackage.haskell.org/trac/haskell-prime/wiki/derivedInstances, April 2007. {Online; accessed 07-June-2010}.Google ScholarGoogle Scholar
  25. }}Noel Winstanley and John Meacham. DrIFT user guide. http://repetae.net/computer/haskell/DrIFT/drift.html, February 2008. {Online; accessed 07-June-2010}.Google ScholarGoogle Scholar

Index Terms

  1. A generic deriving mechanism for Haskell

    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 45, Issue 11
      HASKELL '10
      November 2010
      156 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2088456
      Issue’s Table of Contents
      • cover image ACM Conferences
        Haskell '10: Proceedings of the third ACM Haskell symposium on Haskell
        September 2010
        166 pages
        ISBN:9781450302524
        DOI:10.1145/1863523

      Copyright © 2010 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 30 September 2010

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!