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

Practical generic programming in OCaml

Published:02 October 2007Publication History

ABSTRACT

We describe deriving, a system of extensible generic functions for OCaml implemented as a preprocessor and supporting library. We argue that generating code from type-definitions has significant advantages over a combinator approach, taking serialisation as an example application: our generate-your-boilerplate design results in a system that is easy to use, has comprehensive coverage of types and handles cyclic values without imposing a burden on the user. Users can extend generic functions with specialised implementations at particular types; we show how this can lead to dramatically improved performance in the serialisation task without the user writing a single line of serialisation code.

References

  1. John Billings and Peter Sewell and Mark Shinwell and Rok Strniaš Type-safe distributed programming for OCaml MCM SIGPLAN Workshop on ML, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Jacques Carette, Lydia E. van Dijk and Oleg Kiselyov. Syntactic extension for Monads in Ocaml. http://www.cas.mcmaster.ca/~carette/pa_monad/.Google ScholarGoogle Scholar
  3. James Cheney and Ralf Hinze. A lightweight implementation of generics and dynamics. Haskell Workshop, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Albert Cohen and C. Herrmann. Towards a High-Productivity and High-Performance Marshaling Library for Compound Data. 2nd MetaOCaml Workshop, 2005.Google ScholarGoogle Scholar
  5. Ezra Cooper, Sam Lindley, Philip Wadler, and Jeremy Yallop. Links: Web Programming Without Tiers. FMCO, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Derek Dreyer, Robert Harper, Manuel Chakravarti, and Gabriele Keller. Modular Type Classes. POPL, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Martin Elsman. Type-Specialized Serialization with Sharing. Trends in Functional Programming, 2005.Google ScholarGoogle Scholar
  8. Andrzej Filinski. Controlling Effects. PhD Thesis, School of Computer Science, Carnegie Mellon University, May 1996.Google ScholarGoogle Scholar
  9. Jacques Garrigue. Programming with Polymorphic Variants. ML Workshop, 1998.Google ScholarGoogle Scholar
  10. Jeremy Gibbons. Design patterns as higher-order datatype-generic programs. Workshop on Generic Programming, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Ralf Hinze, Johan Jeuring, and Andres Löh. Comparing approaches to generic programming in Haskell. Spring School on Datatype-Generic Programming, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Ralf Hinze. Generics for the masses. ICFP, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Ralf Hinze, Andres Löh, and Bruno C. d. S. Oliveira. "Scrap Your Boilerplate" Reloaded FLOPS, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. John Hughes. Why Functional Programming Matters. Computer Journal, 32(2), 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Martin Jambon. json-static. http://martin.jambon.free.fr/json-static.html.Google ScholarGoogle Scholar
  16. Martin Jambon. pa tryfinally. http://martin.jambon.free.fr/pa_tryfinally.ml.Google ScholarGoogle Scholar
  17. Patrik Jansson and Johan Jeuring. PolyP -- a polytypic programming language extension. POPL, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Vesa Karvonen. Generics for the Working ML'er. ML Workshop, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. R. Kelsey, W. Clinger, J. Rees (eds.). Revised5 Report on the Algorithmic Language Scheme. Higher-Order and Symbolic Computation, 11(1), 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Andrew J. Kennedy. Functional Pearl: Pickler Combinators. JFP, 14(6), 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Oleg Kiselyov. Post to Haskell list, August 2004. http://haskell.org/pipermail/haskell/2004-August/014463.htmlGoogle ScholarGoogle Scholar
  22. Ralf Lämmel and Simon Peyton-Jones. Scrap your boilerplate: a practical design pattern for generic programming. TLDI, 2003.Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Chuck Liang and Gopalan Nadathur. Tradeoffs in the Intensional Representation of Lambda Terms. RTA, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Neil Mitchell and Stefan O'Rear. Derive. http://www-users.cs.york.ac.uk/~ndm/derive/.Google ScholarGoogle Scholar
  25. Simon Peyton Jones and John Hughes (editors). Haskell 98: A Non-strict, Purely Functional Language. February, 1999.Google ScholarGoogle Scholar
  26. Daniel de Rauglaudre. IoXML. http://cristal.inria.fr/~ddr/IoXML/.Google ScholarGoogle Scholar
  27. Martin Sandin. Tywith. http://tools.assembla.com/tywith/wiki.Google ScholarGoogle Scholar
  28. Guido Tack, Leif Kornstaedt and Gert Smolka. Generic Pickling and Minimization. ML Workshop, 2005.Google ScholarGoogle Scholar
  29. Philip Wadler The essence of functional programming. POPL, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Stefan Wehr. ML Modules and Haskell Type Classes: A Constructive Comparison. Master's thesis, Albert-Ludwigs-Universität, Freiburg, Germany, November 2005.Google ScholarGoogle Scholar
  31. Stephanie Weirich. RepLib: A library for derivable type classes. Haskell Workshop, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Noel Winstanley. DrIFT. http://repetae.net/~john/computer/haskell/DrIFT/.Google ScholarGoogle Scholar
  33. Programming languages - C. ISO/IEC 9899:1999.Google ScholarGoogle Scholar
  34. American National Standard for Programming Language Common LISP. ANSI X3.226:1994. J13/SC22/WG16 Common LISPGoogle ScholarGoogle Scholar

Index Terms

  1. Practical generic programming in OCaml

    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
      ML '07: Proceedings of the 2007 workshop on Workshop on ML
      October 2007
      102 pages
      ISBN:9781595936769
      DOI:10.1145/1292535
      • General Chair:
      • Claudio Russo,
      • Program Chair:
      • Derek Dreyer

      Copyright © 2007 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: 2 October 2007

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • Article

      Acceptance Rates

      Overall Acceptance Rate6of11submissions,55%

      Upcoming Conference

      ICFP '24

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader