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.
- 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 Scholar
Digital Library
- A. Abel. A polymorphic lambda-calculus with sized higher-order types. PhD thesis, Ludwig-Maximilians-Universität München, 2006.Google Scholar
- 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 Scholar
Digital Library
- R. M. Amadio and L. Cardelli. Subtyping recursive types. ACM Trans. Program. Lang. Syst., 15(4):575–631, 1993. Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- J.-P. Bernardy, P. Jansson, and R. Paterson. Proofs for free. Journal of Functional Programming, 22(2):107–152, 2012. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- M. Brandt and F. Henglein. Coinductive axiomatization of recursive type equality and subtyping. Fundam. Inform., 33(4):309–338, 1998. Google Scholar
Digital Library
- B. Bringert and A. Ranta. A pattern for almost compositional functions. Journal of Functional Programming, 18(5-6):567–598, 2008. Google Scholar
Digital Library
- K. B. Bruce, L. Cardelli, and B. C. Pierce. Comparing object encodings. In Theoretical Aspects of Computer Software, pages 415–438. Springer, 1997. Google Scholar
Digital Library
- F. Cardone and M. Coppo. Type inference with recursive types: Syntax and semantics. Information and Computation, 92(1):48–80, May 1991. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- Ł. Czajka. A coinductive confluence proof for infinitary lambdacalculus. In Rewriting and Typed Lambda Calculi, pages 164–178. Springer, 2014.Google Scholar
- 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 Scholar
Digital Library
- D. Dreyer. A type system for recursive modules. In Proceedings of International Conference on Functional Programming, pages 289– 302. ACM, 2007. Google Scholar
Digital Library
- 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 Scholar
- V. Gapeyev, M. Y. Levin, and B. C. Pierce. Recursive subtyping revealed. Journal of Functional Programming, 12(06):511–548, 2002. Google Scholar
Digital Library
- J. Garrigue. Programming with polymorphic variants. In ML Workshop, volume 13. Baltimore, 1998.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- J. Gibbons. Datatype-generic programming. In Spring School on Datatype-Generic Programming. Springer LNCS 4719, 2007. Google Scholar
Digital Library
- J. Gibbons and B. C. d. S. Oliveira. The essence of the Iterator pattern. Journal of Functional Programming, 19:377–402, 2009. Google Scholar
Digital Library
- N. Glew. A theory of second-order trees. In Programming Languages and Systems, pages 147–161. Springer, 2002. Google Scholar
Digital Library
- R. Hinze. Polytypic values possess polykinded types. In Mathematics of Program Construction, pages 2–27. Springer, 2000. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- G. Huet. Regular Böhm trees. Mathematical Structures in Computer Science, 8(06):671–680, 1998. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- E. A. Kmett. The lens package. http://hackage.haskell.org/ package/lens.Google Scholar
- 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 Scholar
Digital Library
- C. McBride and R. Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1–13, 2008. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- N. Oury and W. Swierstra. The power of pi. In ACM Sigplan Notices, volume 43, pages 39–50. ACM, 2008. Google Scholar
Digital Library
- 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 Scholar
- B. C. Pierce. Types and Programming Languages. MIT Press, 2002. Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- G. Sénizergues. Some applications of the decidability of DPDA’s equivalence. In Machines, Computations, and Universality, pages 114–132. Springer, 2001. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- M. Solomon. Type definitions with parameters. In Proceedings of Symposium on Principles of Programming Languages. ACM, 1978. Google Scholar
Digital Library
- C. Stirling. Deciding DPDA equivalence is primitive recursive. In Automata, languages and programming, pages 821–832. Springer, 2002. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- A. K. Wright and M. Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1):38–94, 1994. Google Scholar
Digital Library
Index Terms
System f-omega with equirecursive types for datatype-generic programming
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 ...
Subtyping for f-bounded quantifiers and equirecursive types
Logic and Program Semantics<em>Equirecursive types</em> consider a recursive type to be equal to its unrolling and have no explicit term-level coercions to change a term's type from the former to the latter or vice versa. This equality makes deciding type equality and subtyping ...
Datatype-generic programming meets elaborator reflection
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 ...






Comments