skip to main content

Datatype-generic programming meets elaborator reflection

Published:31 August 2022Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarCross RefCross Ref
  2. Agda Issue. 2022. Loss of Subject Reduction with Setω. https://github.com/agda/agda/issues/5810 Accessed: 2022-03-02 Google ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarCross RefCross Ref
  4. 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 ScholarGoogle ScholarCross RefCross Ref
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarCross RefCross Ref
  7. 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 ScholarGoogle ScholarCross RefCross Ref
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. Richard Bird and Oege de Moor. 1997. Algebra of Programming. Prentice-Hall. isbn:9780135072455 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Edwin Brady. 2017. Type-Driven Development with Idris. Manning Publications. isbn:9781617293023 Google ScholarGoogle Scholar
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarCross RefCross Ref
  14. 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 ScholarGoogle ScholarCross RefCross Ref
  15. 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 ScholarGoogle ScholarCross RefCross Ref
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle Scholar
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. Peter Dybjer. 1994. Inductive Families. Formal Aspects of Computing, 6, 4 (1994), 440–465. https://doi.org/10.1007/BF01211308 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarCross RefCross Ref
  23. 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 ScholarGoogle ScholarCross RefCross Ref
  24. 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 ScholarGoogle ScholarCross RefCross Ref
  25. 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 ScholarGoogle Scholar
  26. 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 ScholarGoogle ScholarCross RefCross Ref
  27. 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 ScholarGoogle ScholarCross RefCross Ref
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle ScholarCross RefCross Ref
  30. 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 ScholarGoogle ScholarCross RefCross Ref
  31. 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 ScholarGoogle Scholar
  32. 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 ScholarGoogle ScholarCross RefCross Ref
  33. Andres Löh. 2004. Exploring Generic Haskell. Ph. D. Dissertation. Utrecht University. https://www.andres-loeh.de/ExploringGH.pdf Google ScholarGoogle Scholar
  34. 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 ScholarGoogle Scholar
  35. 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 ScholarGoogle ScholarCross RefCross Ref
  36. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  37. 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 ScholarGoogle ScholarCross RefCross Ref
  38. Per Martin-Löf. 1984. Intuitionistic Type Theory. Bibliopolis, Napoli. Google ScholarGoogle Scholar
  39. Conor McBride. 2011. Ornamental Algebras, Algebraic Ornaments. https://personal.cis.strath.ac.uk/conor.mcbride/pub/OAAO/LitOrn.pdf Google ScholarGoogle Scholar
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. Fredrik Nordvall Forsberg. 2013. Inductive-inductive definitions. Ph. D. Dissertation. Swansea University. Google ScholarGoogle Scholar
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  45. 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 ScholarGoogle ScholarCross RefCross Ref
  46. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  47. 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 ScholarGoogle ScholarCross RefCross Ref
  48. Aaron Stump. 2016. Verified Functional Programming in Agda. ACM Books. isbn:9781970001242 https://doi.org/10.1145/2841316 Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  50. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  51. 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 ScholarGoogle Scholar

Index Terms

  1. Datatype-generic programming meets elaborator reflection

      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

      • Article Metrics

        • Downloads (Last 12 months)382
        • Downloads (Last 6 weeks)35

        Other Metrics

      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!