Abstract
Datatype-generic programming is natural and useful in dependently typed languages such as Agda. However, datatype-generic libraries in Agda are not reused as much as they should be, because traditionally they work only on datatypes decoded from a library’s own version of datatype descriptions; this means that different generic libraries cannot be used together, and they do not work on native datatypes, which are preferred by the practical Agda programmer for better language support and access to other libraries. Based on elaborator reflection, we present a framework in Agda featuring a set of general metaprograms for instantiating datatype-generic programs as, and for, a useful range of native datatypes and functions —including universe-polymorphic ones— in programmer-friendly and customisable forms. We expect that datatype-generic libraries built with our framework will be more attractive to the practical Agda programmer. As the elaborator reflection features used by our framework become more widespread, our design can be ported to other languages too.
- Faris Abou-Saleh, James Cheney, Jeremy Gibbons, James McKinna, and Perdita Stevens. 2018. Introduction to Bidirectional Transformations. In International Summer School on Bidirectional Transformations (SSBX) 2016 (Lecture Notes in Computer Science, Vol. 9715). Springer, 1–28. https://doi.org/10.1007/978-3-319-79108-1_1
Google Scholar
Cross Ref
- Agda Issue. 2022. Loss of Subject Reduction with Setω. https://github.com/agda/agda/issues/5810 Accessed: 2022-03-02
Google Scholar
- Artem Alimarine and Sjaak Smetsers. 2004. Optimizing Generic Functions. In International Conference on Mathematics of Program Construction (MPC) (Lecture Notes in Computer Science, Vol. 3125). Springer, 16–31. https://doi.org/10.1007/978-3-540-27764-4_3
Google Scholar
Cross Ref
- Guillaume Allais, Robert Atkey, James Chapman, Conor McBride, and James McKinna. 2021. A Type- and Scope-Safe Universe of Syntaxes with Binding: Their Semantics and Proofs. Journal of Functional Programming, 31 (2021), e22:1–51. https://doi.org/10.1017/S0956796820000076
Google Scholar
Cross Ref
- Uri Alon, Meital Zilberstein, Omer Levy, and Eran Yahav. 2019. code2vec: Learning Distributed Representations of Code. Proceedings of the ACM on Programming Languages, 3, POPL (2019), 40:1–29. https://doi.org/10.1145/3290353
Google Scholar
Digital Library
- Thorsten Altenkirch and Conor McBride. 2003. Generic Programming within Dependently Typed Programming. In Generic Programming (IFIP — The International Federation for Information Processing, Vol. 115). Springer, 1–20. https://doi.org/10.1007/978-0-387-35672-3_1
Google Scholar
Cross Ref
- Thorsten Altenkirch, Conor McBride, and Peter Morris. 2007. Generic Programming with Dependent Types. In International Spring School on Datatype-Generic Programming (SSDGP) 2006 (Lecture Notes in Computer Science, Vol. 4719). Springer, 209–257. https://doi.org/10.1007/978-3-540-76786-2_4
Google Scholar
Cross Ref
- Marcin Benke, Peter Dybjer, and Patrik Jansson. 2003. Universes for Generic Programs and Proofs in Dependent Type Theory. Nordic Journal of Computing, 10, 4 (2003), 265–289. https://www.mimuw.edu.pl/~ben/Papers/universes.pdf
Google Scholar
Digital Library
- Richard Bird and Oege de Moor. 1997. Algebra of Programming. Prentice-Hall. isbn:9780135072455
Google Scholar
Digital Library
- Edwin Brady. 2017. Type-Driven Development with Idris. Manning Publications. isbn:9781617293023
Google Scholar
- James Chapman, Pierre-Évariste Dagand, Conor McBride, and Peter Morris. 2010. The Gentle Art of Levitation. In International Conference on Functional Programming (ICFP). ACM, 3–14. https://doi.org/10.1145/1863543.1863547
Google Scholar
Digital Library
- David Christiansen and Edwin Brady. 2016. Elaborator Reflection: Extending Idris in Idris. In International Conference on Functional Programming (ICFP). ACM, 284–297. https://doi.org/10.1145/3022670.2951932
Google Scholar
Digital Library
- Jesper Cockx and Andreas M. Abel. 2020. Elaborating Dependent (Co)pattern Matching: No Pattern Left Behind. Journal of Functional Programming, 30 (2020), e2:1–43. https://doi.org/10.1017/S0956796819000182
Google Scholar
Cross Ref
- Jesper Cockx, Dominique Devriese, and Frank Piessens. 2016. Eliminating Dependent Pattern Matching without K. Journal of Functional Programming, 26 (2016), e16:1–40. https://doi.org/10.1017/S0956796816000174
Google Scholar
Cross Ref
- Pierre-Évariste Dagand and Conor McBride. 2014. Transporting Functions across Ornaments. Journal of Functional Programming, 24, 2–3 (2014), 316–383. https://doi.org/10.1017/S0956796814000069
Google Scholar
Cross Ref
- N. G. de Bruijn. 1991. Telescopic Mappings in Typed Lambda Calculus. Information and Computation, 91, 2 (1991), 189–204. https://doi.org/10.1016/0890-5401(91)90066-b
Google Scholar
Digital Library
- Edsko de Vries and Andres Löh. 2014. True Sums of Products. In Workshop on Generic Programming (WGP). ACM, 83–94. https://doi.org/10.1145/2633628.2633634
Google Scholar
Digital Library
- Martijn de Vries. 2004. Specializing Type-Indexed Values by Partial Evaluation. Master’s thesis. University of Groningen. https://fse.studenttheses.ub.rug.nl/8943/
Google Scholar
- Dominique Devriese and Frank Piessens. 2011. On the Bright Side of Type Classes: Instance Arguments in Agda. In International Conference on Functional Programming (ICFP). ACM, 143–155. https://doi.org/10.1145/2034773.2034796
Google Scholar
Digital Library
- Larry Diehl and Tim Sheard. 2016. Generic Lookup and Update for Infinitary Inductive-Recursive Types. In Workshop on Type-Driven Development (TyDe). ACM, 1–12. https://doi.org/10.1145/2976022.2976031
Google Scholar
Digital Library
- Peter Dybjer. 1994. Inductive Families. Formal Aspects of Computing, 6, 4 (1994), 440–465. https://doi.org/10.1007/BF01211308
Google Scholar
Digital Library
- Peter Dybjer and Anton Setzer. 2006. Indexed Induction-Recursion. Journal of Logic and Algebraic Programming, 66, 1 (2006), 1–49. https://doi.org/10.1016/j.jlap.2005.07.001
Google Scholar
Cross Ref
- Andrzej Filinski. 1999. A Semantic Account of Type-Directed Partial Evaluation. In International Conference on Principles and Practice of Declarative Programming (PPDP) (Lecture Notes in Computer Science, Vol. 1702). Springer, 378–395. https://doi.org/10.1007/10704567_23
Google Scholar
Cross Ref
- Jeremy Gibbons. 2007. Datatype-Generic Programming. In International Spring School on Datatype-Generic Programming (SSDGP) 2006 (Lecture Notes in Computer Science, Vol. 4719). Springer, 1–71. https://doi.org/10.1007/978-3-540-76786-2_1
Google Scholar
Cross Ref
- Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. 1993. Partial Evaluation and Automatic Program Generation. Prentice-Hall. isbn:9780130202499 https://www.itu.dk/people/sestoft/pebook/
Google Scholar
- Ambrus Kaposi and András Kovács. 2020. Signatures and Induction Principles for Higher Inductive-Inductive Types. Logical Methods in Computer Science, 16, 1 (2020), 10:1–30. https://doi.org/10.23638/LMCS-16(1:10)2020
Google Scholar
Cross Ref
- Hsiang-Shang Ko. 2021. Programming Metamorphic Algorithms: An Experiment in Type-driven Algorithm Design. The Art, Science, and Engineering of Programming, 5, 2 (2021), 7:1–34. https://doi.org/10.22152/programming-journal.org/2021/5/7
Google Scholar
Cross Ref
- Hsiang-Shang Ko, Liang-Ting Chen, and Tzu-Chi Lin. 2022. Datatype-Generic Programming Meets Elaborator Reflection (Artefact). https://doi.org/10.5281/zenodo.6954977
Google Scholar
Digital Library
- Hsiang-Shang Ko and Jeremy Gibbons. 2013. Modularising Inductive Families. Progress in Informatics, 10 (2013), 65–88. https://doi.org/10.2201/NiiPi.2013.10.5
Google Scholar
Cross Ref
- Hsiang-Shang Ko and Jeremy Gibbons. 2017. Programming with Ornaments. Journal of Functional Programming, 27 (2017), e2:1–43. https://doi.org/10.1017/S0956796816000307
Google Scholar
Cross Ref
- Wen Kokke, Philip Wadler, and Jeremy G. Siek. 2020. Programming Language Foundations in Agda (Version 20.07). http://plfa.inf.ed.ac.uk/20.07/
Google Scholar
- András Kovács. 2022. Generalized Universe Hierarchies and First-Class Universe Levels. In Conference on Computer Science Logic (CSL) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 216). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 28:1–17. https://doi.org/10.4230/LIPIcs.CSL.2022.28
Google Scholar
Cross Ref
- Andres Löh. 2004. Exploring Generic Haskell. Ph. D. Dissertation. Utrecht University. https://www.andres-loeh.de/ExploringGH.pdf
Google Scholar
- José Pedro Magalhães. 2012. Less Is More: Generic Programming Theory and Practice. Ph. D. Dissertation. Utrecht University. https://dreixel.net/research/pdf/thesis.pdf
Google Scholar
- José Pedro Magalhães. 2013. Optimisation of Generic Programs through Inlining. In Symposium on Implementation and Application of Functional Languages (IFL) (Lecture Notes in Computer Science, Vol. 8241). Springer, 104–121. https://doi.org/10.1007/978-3-642-41582-1_7
Google Scholar
Cross Ref
- José Pedro Magalhães and Andres Löh. 2014. Generic Generic Programming. In International Symposium on Practical Aspects of Declarative Languages (PADL) (Lecture Notes in Computer Science, Vol. 8324). Springer, 216–231. https://doi.org/10.1007/978-3-319-04132-2_15
Google Scholar
Digital Library
- Per Martin-Löf. 1975. An Intuitionistic Theory of Types: Predicative Part. In Logic Colloquium ’73 (Studies in Logic and the Foundations of Mathematics, Vol. 80). Elsevier, 73–118. https://doi.org/10.1016/S0049-237X(08)71945-1
Google Scholar
Cross Ref
- Per Martin-Löf. 1984. Intuitionistic Type Theory. Bibliopolis, Napoli.
Google Scholar
- Conor McBride. 2011. Ornamental Algebras, Algebraic Ornaments. https://personal.cis.strath.ac.uk/conor.mcbride/pub/OAAO/LitOrn.pdf
Google Scholar
- Conor McBride. 2014. How to Keep Your Neighbours in Order. In International Conference on Functional Programming (ICFP). ACM, 297–309. https://doi.org/10.1145/2628136.2628163
Google Scholar
Digital Library
- Aleksandar Nanevski and Frank Pfenning. 2005. Staged Computation with Names and Necessity. Journal of Functional Programming, 15, 6 (2005), 893–939. https://doi.org/10.1017/S095679680500568X
Google Scholar
Digital Library
- Fredrik Nordvall Forsberg. 2013. Inductive-inductive definitions. Ph. D. Dissertation. Swansea University.
Google Scholar
- Matthew Pickering, Gergo Gergő Érdi, Simon Peyton Jones, and Richard A. Eisenberg. 2016. Pattern Synonyms. In International Symposium on Haskell. ACM, 80–91. https://doi.org/10.1145/2976002.2976013
Google Scholar
Digital Library
- Matthew Pickering, Andres Löh, and Nicolas Wu. 2020. Staged Sums of Products. In International Symposium on Haskell. ACM, 122–135. https://doi.org/10.1145/3406088.3409021
Google Scholar
Digital Library
- Talia Ringer, Nathaniel Yazdani, John Leo, and Dan Grossman. 2019. Ornaments for Proof Reuse in Coq. In International Conference on Interactive Theorem Proving (ITP) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 141). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 26:1–19. https://doi.org/10.4230/LIPIcs.ITP.2019.26
Google Scholar
Cross Ref
- Carsten Schürmann, Adam Poswolsky, and Jeffrey Sarnat. 2005. The ∇-Calculus. Functional Programming with Higher-Order Encodings. In International Conference on Typed Lambda Calculi and Applications (TLCA) (Lecture Notes in Computer Science, Vol. 3461). Springer. https://doi.org/10.1007/11417170_2
Google Scholar
Digital Library
- Matthieu Sozeau and Nicolas Tabareau. 2014. Universe Polymorphism in Coq. In International Conference on Interactive Theorem Proving (ITP) (Lecture Notes in Computer Science, Vol. 8558). Springer, 499–514. https://doi.org/10.1007/978-3-319-08970-6_32
Google Scholar
Cross Ref
- Aaron Stump. 2016. Verified Functional Programming in Agda. ACM Books. isbn:9781970001242 https://doi.org/10.1145/2841316
Google Scholar
Digital Library
- Thomas Williams and Didier Rémy. 2018. A Principled Approach to Ornamentation in ML. Proceedings of the ACM on Programming Languages, 2, POPL (2018), 21:1–30. https://doi.org/10.1145/3158109
Google Scholar
Digital Library
- Jeremy Yallop. 2017. Staged Generic Programming. Proceedings of the ACM on Programming Languages, 1, ICFP (2017), 29:1–29. https://doi.org/10.1145/3110273
Google Scholar
Digital Library
- Zhixuan Yang and Nicolas Wu. 2022. Fantastic Morphisms and Where to Find Them: A Guide to Recursion Schemes. To appear at the International Conference on Mathematics of Program Construction (MPC). arxiv:2202.13633
Google Scholar
Index Terms
Datatype-generic programming meets elaborator reflection
Recommendations
System f-omega with equirecursive types for datatype-generic programming
POPL '16: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming LanguagesTraversing an algebraic datatype by hand requires boilerplate code which duplicates the structure of the datatype. Datatype-generic programming (DGP) aims to eliminate such boilerplate code by decomposing algebraic datatypes into type constructor ...
System f-omega with equirecursive types for datatype-generic programming
POPL '16Traversing an algebraic datatype by hand requires boilerplate code which duplicates the structure of the datatype. Datatype-generic programming (DGP) aims to eliminate such boilerplate code by decomposing algebraic datatypes into type constructor ...
Modularising inductive families
WGP '11: Proceedings of the seventh ACM SIGPLAN workshop on Generic programmingDependently typed programmers are encouraged to use inductive families to integrate constraints with data construction. Different constraints are used in different contexts, leading to different versions of datatypes for the same data structure. Modular ...






Comments