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.
Supplemental Material
Available for Download
Appendix to the main paper.
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Baldur Blöndal, Andres Löh, and Ryan Scott. 2018. Deriving Via. In Proceedings of the 11th ACM Haskell Symposium (Haskell '18).Google Scholar
- Max Bolingbroke. 2011. Constraint Kinds for GHC. http://blog.omega-prime.co.uk/?p=127 Blog post.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Jean-Yves Girard. 1972. Interpretation fonctionnelle et elimination des coupures de l'arithmetique d'ordre superieur. Ph.D. Dissertation.Google Scholar
- 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 Scholar
Digital Library
- Ralf Hinze. 2000. Polytypic Values Possess Polykinded Types. In Mathematics of Program Construction. Springer Berlin Heidelberg. Google Scholar
Digital Library
- Ralf Hinze and Johan Jeuring. 2003. Generic Haskell: Applications. Springer Berlin Heidelberg, Berlin, Heidelberg.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- Simon Marlow et al. 2010. Haskell 2010 Language Report. https://www.haskell.org/onlinereport/haskell2010/.Google Scholar
- Conor McBride. 2013. Dependently typed metaprogramming (in Agda), Lecture Notes.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Stephanie Weirich, Justin Hsu, and Richard A. Eisenberg. 2013. System FC with Explicit Kind Equality. SIGPLAN Not. 48, 9 (Sept. 2013). Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Generic programming of all kinds
Recommendations
Generic programming of all kinds
Haskell 2018: Proceedings of the 11th ACM SIGPLAN International Symposium on HaskellDatatype-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 ...
The right kind of generic programming
WGP '12: Proceedings of the 8th ACM SIGPLAN workshop on Generic programmingHaskell is known for its strong, static type system. A good type system classifies values, constraining the valid terms of the language and preventing many common programming errors. The Glasgow Haskell Compiler (GHC) has further extended the type ...
Generic constructors and eliminators from descriptions: type theory as a dependently typed internal DSL
WGP '14: Proceedings of the 10th ACM SIGPLAN workshop on Generic programmingDependently typed languages with an "open" type theory introduce new datatypes using an axiomatic approach. Each new datatype introduces axioms for constructing values of the datatype, and an elimination axiom (which we call the standard eliminator) for ...







Comments