skip to main content
article

Generic programming of all kinds

Published:17 September 2018Publication History
Skip Abstract Section

Abstract

Datatype-generic programming is a widely used technique to define functions that work regularly over a class of datatypes. Examples include deriving serialization of data, equality or even functoriality. The state-of-the-art of generic programming still lacks handling GADTs, multiple type variables, and some other features. This paper exploits modern GHC extensions, including <pre>TypeInType</pre>, to handle arbitrary number of type variables, constraints, and existentials. We also provide an Agda model of our construction that does not require Russel’s paradox, proving the construction is consistent.

Skip Supplemental Material Section

Supplemental Material

References

  1. Thorsten Altenkirch, Conor McBride, and Peter Morris. 2007. Generic Programming with Dependent Types. In Proceedings of the 2006 International Conference on Datatype-generic Programming (SSDGP'06). Springer-Verlag, Berlin, Heidelberg. http://dl.acm.org/citation.cfm?id=1782894.1782898Google ScholarGoogle ScholarCross RefCross Ref
  2. Thorsten Altenkirch and Bernhard Reus. 1999. Monadic Presentations of Lambda Terms Using Generalized Inductive Types. In Proceedings of the 13th International Workshop and 8th Annual Conference of the EACSL on Computer Science Logic (CSL '99). http://dl.acm.org/citation.cfm?id=647849.737066 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Nick Benton, Chung-Kil Hur, Andrew J. Kennedy, and Conor McBride. 2012. Strongly Typed Term Representations in Coq. J. Autom. Reason. 49, 2 (Aug. 2012), 19. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Richard S. Bird and Lambert G. L. T. Meertens. 1998. Nested Datatypes. In Proceedings of the Mathematics of Program Construction (MPC '98). http://dl.acm.org/citation.cfm?id=648084.747162 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Baldur Blöndal, Andres Löh, and Ryan Scott. 2018. Deriving Via. In Proceedings of the 11th ACM Haskell Symposium (Haskell '18).Google ScholarGoogle Scholar
  6. Max Bolingbroke. 2011. Constraint Kinds for GHC. http://blog.omega-prime.co.uk/?p=127 Blog post.Google ScholarGoogle Scholar
  7. Gert-Jan Bottu, Georgios Karachalias, Tom Schrijvers, Bruno C. d. S. Oliveira, and Philip Wadler. 2017. Quantified Class Constraints. In Proceedings of the 10th ACM SIGPLAN International Symposium on Haskell (Haskell 2017). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Edsko de Vries and Andres Löh. 2014. True Sums of Products. In Proceedings of the 10th ACM SIGPLAN Workshop on Generic Programming (WGP '14). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Richard A. Eisenberg and Stephanie Weirich. 2012. Dependently Typed Programming with Singletons. In Proceedings of the 2012 Haskell Symposium (Haskell '12). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application. In 25th European Symposium on Programming, ESOP 2016, Eindhoven, The Netherlands, April 2-8. Springer. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Jean-Yves Girard. 1972. Interpretation fonctionnelle et elimination des coupures de l'arithmetique d'ordre superieur. Ph.D. Dissertation.Google ScholarGoogle Scholar
  12. Ralf Hinze. 2000. A New Approach to Generic Functional Programming. In Proceedings of the 27th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '00). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Ralf Hinze. 2000. Polytypic Values Possess Polykinded Types. In Mathematics of Program Construction. Springer Berlin Heidelberg. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Ralf Hinze and Johan Jeuring. 2003. Generic Haskell: Applications. Springer Berlin Heidelberg, Berlin, Heidelberg.Google ScholarGoogle Scholar
  15. Ralf Lämmel and Simon Peyton Jones. 2003. Scrap Your Boilerplate: A Practical Design Pattern for Generic Programming. In Proceedings of the 2003 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI '03). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Eelco Lempsink, Sean Leather, and Andres Löh. 2009. Type-safe Diff for Families of Datatypes. In Proceedings of the 2009 ACM SIGPLAN Workshop on Generic Programming (WGP '09). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. José Pedro Magalhães, Atze Dijkstra, Johan Jeuring, and Andres Löh. 2010. A Generic Deriving Mechanism for Haskell. In Proceedings of the Third ACM Haskell Symposium (Haskell '10). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. José Pedro Magalhães and Johan Jeuring. 2011. Generic Programming for Indexed Datatypes. In Proceedings of the Seventh ACM SIGPLAN Workshop on Generic Programming (WGP '11). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. José Pedro Magalhães and Andres Löh. 2012. A Formal Comparison of Approaches to Datatype-Generic Programming. In Proceedings Fourth Workshop on Mathematically Structured Functional Programming, Tallinn, Estonia, 25 March 2012, James Chapman and Paul Blain Levy (Eds.).Google ScholarGoogle ScholarCross RefCross Ref
  20. José Pedro Magalhães and Andres Löh. 2014. Generic Generic Programming. In Practical Aspects of Declarative Languages, Matthew Flatt and Hai-Feng Guo (Eds.). Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Simon Marlow et al. 2010. Haskell 2010 Language Report. https://www.haskell.org/onlinereport/haskell2010/.Google ScholarGoogle Scholar
  22. Conor McBride. 2013. Dependently typed metaprogramming (in Agda), Lecture Notes.Google ScholarGoogle Scholar
  23. Victor Cacciari Miraldo, Pierre-Évariste Dagand, and Wouter Swierstra. 2017. Type-directed Diffing of Structured Data. In Proceedings of the 2nd ACM SIGPLAN Workshop on Type-Driven Development (TyDe 2017). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Victor Cacciari Miraldo and Alejandro Serrano. 2018. Sums of Products for Mutually Recursive Datatypes. In Proceedings of the 3nd ACM SIGPLAN Workshop on Type-Driven Development (TyDe 2018). Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Neil Mitchell and Colin Runciman. 2007. Uniform Boilerplate and List Processing. In Proceedings of the ACM SIGPLAN Workshop on Haskell Workshop (Haskell '07). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Thomas van Noort, Alexey Rodriguez, Stefan Holdermans, Johan Jeuring, and Bastiaan Heeren. 2008. A Lightweight Approach to Datatype-generic Rewriting. In Proceedings of the ACM SIGPLAN Workshop on Generic Programming (WGP '08). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Simon Peyton Jones, Stephanie Weirich, Richard A. Eisenberg, and Dimitrios Vytiniotis. 2016. A Reflection on Types. In A List of Successes That Can Change the World - Essays Dedicated to Philip Wadler on the Occasion of His 60th Birthday.Google ScholarGoogle Scholar
  28. Alexey Rodriguez, Johan Jeuring, Patrik Jansson, Alex Gerdes, Oleg Kiselyov, and Bruno C. d. S. Oliveira. 2008. Comparing Libraries for Generic Programming in Haskell. In Proceedings of the First ACM SIGPLAN Symposium on Haskell (Haskell '08). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Ryan Scott. 2018. How to derive Generic for (some) GADTs using Quantified Constraints. Blog post, available at https://ryanglscott.github.io/2018/02/11/how-to-derive-generic-for-some-gadts/.Google ScholarGoogle Scholar
  30. Alejandro Serrano and Jurriaan Hage. 2016. Generic Matching of Tree Regular Expressions over Haskell Data Types. In Practical Aspects of Declarative Languages - 18th International Symposium, PADL 2016, St. Petersburg, FL, USA, January 18-19, 2016. Proceedings.Google ScholarGoogle Scholar
  31. Tim Sheard and Simon Peyton Jones. 2002. Template metaprogramming for Haskell. https://www.microsoft.com/en-us/research/publication/template-meta-programming-for-haskell/ Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Stephanie Weirich and Chris Casinghino. 2010. Arity-generic Datatype-generic Programming. In Proceedings of the 4th ACM SIGPLAN Workshop on Programming Languages Meets Program Verification (PLPV '10). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Stephanie Weirich, Justin Hsu, and Richard A. Eisenberg. 2013. System FC with Explicit Kind Equality. SIGPLAN Not. 48, 9 (Sept. 2013). Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Stephanie Weirich, Antoine Voizard, Pedro Henrique Azevedo de Amorim, and Richard A. Eisenberg. 2017. A Specification for Dependent Types in Haskell. Proc. ACM Program. Lang. 1, ICFP (Aug. 2017). Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Thomas Winant, Dominique Devriese, Frank Piessens, and Tom Schrijvers. 2014. Partial Type Signatures for Haskell. In Practical Aspects of Declarative Languages, Matthew Flatt and Hai-Feng Guo (Eds.). Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded Recursive Datatype Constructors. In Proceedings of the 30th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '03). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Alexey Rodriguez Yakushev, Stefan Holdermans, Andres Löh, and Johan Jeuring. 2009. Generic Programming with Fixed Points for Mutually Recursive Datatypes. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming (ICFP '09). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. 2012. Giving Haskell a Promotion. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI '12). ACM, New York, NY, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Generic programming of all kinds

      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 53, Issue 7
        Haskell '18
        July 2018
        185 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/3299711
        Issue’s Table of Contents
        • cover image ACM Conferences
          Haskell 2018: Proceedings of the 11th ACM SIGPLAN International Symposium on Haskell
          September 2018
          185 pages
          ISBN:9781450358354
          DOI:10.1145/3242744

        Copyright © 2018 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 17 September 2018

        Check for updates

        Qualifiers

        • 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!