skip to main content
article

System f-omega with equirecursive types for datatype-generic programming

Published:11 January 2016Publication History
Skip Abstract Section

Abstract

Traversing 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 applications from which generic traversals can be synthesized. However, different traversals require different decompositions, which yield isomorphic but unequal types. This hinders the interoperability of different DGP techniques. In this paper, we propose Fωμ, an extension of the higher-order polymorphic lambda calculus Fω with records, variants, and equirecursive types. We prove the soundness of the type system, and show that type checking for first-order recursive types is decidable with a practical type checking algorithm. In our soundness proof we define type equality by interpreting types as infinitary λ-terms (in particular, Berarducci-trees). To decide type equality we β-normalize types, and then use an extension of equivalence checking for usual equirecursive types. Thanks to equirecursive types, new decompositions for a datatype can be added modularly and still interoperate with each other, allowing multiple DGP techniques to work together. We sketch how generic traversals can be synthesized, and apply these components to some examples. Since the set of datatype decomposition becomes extensible, System Fωμ enables using DGP techniques incrementally, instead of planning for them upfront or doing invasive refactoring.

References

  1. M. Abadi and M. P. Fiore. Syntactic considerations on recursive types. In Proceedings of the 11th Annual IEEE Symposium on Logic in Computer Science, pages 242–252. IEEE Computer Society, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. Abel. A polymorphic lambda-calculus with sized higher-order types. PhD thesis, Ludwig-Maximilians-Universität München, 2006.Google ScholarGoogle Scholar
  3. T. Altenkirch, C. McBride, and P. Morris. Generic programming with dependent types. In Datatype-Generic Programming, pages 209– 257. Springer, 2007. Revised lectures of International Spring School SSDGP 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. R. M. Amadio and L. Cardelli. Subtyping recursive types. ACM Trans. Program. Lang. Syst., 15(4):575–631, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. F. Atanassow and J. Jeuring. Inferring Type Isomorphisms Generically. In D. Kozen, editor, Mathematics of Program Construction, volume 3125 of Lecture Notes in Computer Science, chapter 4, pages 32–53. Springer Berlin / Heidelberg, 2004.Google ScholarGoogle Scholar
  6. M. Benke, P. Dybjer, and P. Jansson. Universes for generic programs and proofs in dependent type theory. Nordic Journal of Computing, 10(4):265–289, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. A. Berarducci. Infinite-calculus and non-sensible models. In A. Ursini and P. Agliano, editors, Logic and Algebra (Pontignano, 1994), volume 180 of Lecture Notes in Pure and Applied Mathematics, pages 339–378. Marcel Dekker Inc., 1996.Google ScholarGoogle Scholar
  8. J.-P. Bernardy and M. Lasson. Realizability and parametricity in pure type systems. In Foundations of Software Science and Computational Structures, pages 108–122. Springer LNCS 6604, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. J.-P. Bernardy, P. Jansson, and R. Paterson. Proofs for free. Journal of Functional Programming, 22(2):107–152, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. R. Bird and L. Meertens. Nested datatypes. In J. Jeuring, editor, Mathematics of Program Construction, number 1422 in Lecture Notes in Computer Science, pages 52–67. Springer Berlin Heidelberg, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. M. Brandt and F. Henglein. Coinductive axiomatization of recursive type equality and subtyping. In P. d. Groote and J. R. Hindley, editors, Typed Lambda Calculi and Applications, number 1210 in Lecture Notes in Computer Science, pages 63–81. Springer Berlin Heidelberg, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. M. Brandt and F. Henglein. Coinductive axiomatization of recursive type equality and subtyping. Fundam. Inform., 33(4):309–338, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. B. Bringert and A. Ranta. A pattern for almost compositional functions. Journal of Functional Programming, 18(5-6):567–598, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. K. B. Bruce, L. Cardelli, and B. C. Pierce. Comparing object encodings. In Theoretical Aspects of Computer Software, pages 415–438. Springer, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. F. Cardone and M. Coppo. Type inference with recursive types: Syntax and semantics. Information and Computation, 92(1):48–80, May 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. D. Colazzo and G. Ghelli. Subtyping recursive types in kernel Fun. In Proceedings of Symposium on Logic in Computer Science, pages 137–146. IEEE, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Ł. Czajka. A coinductive confluence proof for infinitary lambdacalculus. In Rewriting and Typed Lambda Calculi, pages 164–178. Springer, 2014.Google ScholarGoogle Scholar
  18. E. de Vries and A. Löh. True sums of products. In Proceedings of the 10th ACM SIGPLAN Workshop on Generic Programming, pages 83–94. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. D. Dreyer. A type system for recursive modules. In Proceedings of International Conference on Functional Programming, pages 289– 302. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. J. Endrullis and A. Polonsky. Infinitary Rewriting Coinductively. In N. A. Danielsson and B. Nordström, editors, 18th International Workshop on Types for Proofs and Programs (TYPES 2011), volume 19 of Leibniz International Proceedings in Informatics (LIPIcs), pages 16– 27. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, 2013.Google ScholarGoogle Scholar
  21. V. Gapeyev, M. Y. Levin, and B. C. Pierce. Recursive subtyping revealed. Journal of Functional Programming, 12(06):511–548, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. J. Garrigue. Programming with polymorphic variants. In ML Workshop, volume 13. Baltimore, 1998.Google ScholarGoogle Scholar
  23. N. Gauthier and F. Pottier. Numbering matters: First-order canonical forms for second-order recursive types. In Proceedings of International Conference on Functional Programming, pages 150–161. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. J. Gibbons. Design patterns as higher-order datatype-generic programs. In Proceedings of the 2006 ACM SIGPLAN workshop on Generic programming, pages 1–12. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. J. Gibbons. Datatype-generic programming. In Spring School on Datatype-Generic Programming. Springer LNCS 4719, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. J. Gibbons and B. C. d. S. Oliveira. The essence of the Iterator pattern. Journal of Functional Programming, 19:377–402, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. N. Glew. A theory of second-order trees. In Programming Languages and Systems, pages 147–161. Springer, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. R. Hinze. Polytypic values possess polykinded types. In Mathematics of Program Construction, pages 2–27. Springer, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. S. Holdermans, J. Jeuring, A. Löh, and A. Rodriguez Yakushev. Generic views on data types. In Mathematics of Program Construction, pages 209–234. Springer, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. G. Huet. Regular Böhm trees. Mathematical Structures in Computer Science, 8(06):671–680, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. H. Im, K. Nakata, and S. Park. Contractive signatures with recursive types, type parameters, and abstract types. In Automata, Languages, and Programming, pages 299–311. Springer, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. P. Jancar. Decidability of DPDA language equivalence via first-order grammars. In Proceedings of the 2012 27th Annual IEEE/ACM Symposium on Logic in Computer Science, pages 415–424. IEEE Computer Society, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. M. Jaskelioff and O. Rypacek. An investigation of the laws of traversals. In Proceedings of the Fourth Workshop on Mathematically Structured Functional Programming, volume 76, pages 40–49. Open Publishing Association, 2012.Google ScholarGoogle Scholar
  34. J. Kennaway, J. W. Klop, M. R. Sleep, and F.-J. de Vries. Infinitary lambda calculus. Theoretical Computer Science, 175(1):93–125, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. E. A. Kmett. The lens package. http://hackage.haskell.org/ package/lens.Google ScholarGoogle Scholar
  36. R. Lämmel and S. Peyton Jones. 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, pages 26–37. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1–13, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. E. Meijer, M. Fokkinga, and R. Paterson. Functional programming with bananas, lenses, envelopes and barbed wire. In Functional Programming Languages and Computer Architecture, pages 124–144. Springer LNCS 523, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. N. Mitchell and C. Runciman. Uniform boilerplate and list processing. In Proceedings of the ACM SIGPLAN workshop on Haskell, pages 49– 60. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. U. Norell. Dependently typed programming in agda. In Advanced Functional Programming, pages 230–266. Springer, 2009. Revised lectures of the 4th International School AFP 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. N. Oury and W. Swierstra. The power of pi. In ACM Sigplan Notices, volume 43, pages 39–50. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. F. Pfenning. Lecture notes on bidirectional type checking. In Carnegie Mellon University course 15-312, “Foundations of programming languages,” fall 2004. http://www.cs.cmu.edu/~fp/courses/ 15312-f04/handouts/15-bidirectional.pdf, retrieved on 10 July 2015.Google ScholarGoogle Scholar
  43. B. C. Pierce. Types and Programming Languages. MIT Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. F. Pottier. {TYPES} System F omega with (equi-)recursive types. http://lists.seas.upenn.edu/pipermail/types-list/ 2011/001525.html, 2011. Retrieved on 2 July 2015.Google ScholarGoogle Scholar
  45. A. Rodriguez Yakushev, S. Holdermans, A. Löh, and J. Jeuring. Generic programming with fixed points for mutually recursive datatypes. In Proceedings of International Conference on Functional Programming, pages 233–244. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. G. Sénizergues. Some applications of the decidability of DPDA’s equivalence. In Machines, Computations, and Universality, pages 114–132. Springer, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Z. Shao, C. League, and S. Monnier. Implementing typed intermediate languages. In Proceedings of International Conference on Functional Programming, pages 313–323. ACM, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. M. Solomon. Type definitions with parameters. In Proceedings of Symposium on Principles of Programming Languages. ACM, 1978. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. C. Stirling. Deciding DPDA equivalence is primitive recursive. In Automata, languages and programming, pages 821–832. Springer, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. P. Tarr, H. Ossher, W. Harrison, and S. M. Sutton, Jr. N degrees of separation: Multi-dimensional separation of concerns. In Proceedings of the 21st International Conference on Software Engineering, pages 107–119. ACM, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. A. K. Wright and M. Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1):38–94, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. System f-omega with equirecursive types for datatype-generic programming

        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 51, Issue 1
          POPL '16
          January 2016
          815 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2914770
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            POPL '16: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages
            January 2016
            815 pages
            ISBN:9781450335492
            DOI:10.1145/2837614

          Copyright © 2016 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 11 January 2016

          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!