Nothing Special   »   [go: up one dir, main page]

skip to main content
10.1145/2837614.2837660acmconferencesArticle/Chapter ViewAbstractPublication PagespoplConference Proceedingsconference-collections
research-article

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

Published: 11 January 2016 Publication History

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

Cited By

View all

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

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
  • 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
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Sponsors

In-Cooperation

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 11 January 2016

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Datatype-generic programming
  2. equirecursive types
  3. functors

Qualifiers

  • Research-article

Conference

POPL '16
Sponsor:

Acceptance Rates

Overall Acceptance Rate 824 of 4,130 submissions, 20%

Upcoming Conference

POPL '25

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)32
  • Downloads (Last 6 weeks)7
Reflects downloads up to 30 Nov 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Full Iso-Recursive TypesProceedings of the ACM on Programming Languages10.1145/36897188:OOPSLA2(192-221)Online publication date: 8-Oct-2024
  • (2024)Polymorphic higher-order context-free session typesTheoretical Computer Science10.1016/j.tcs.2024.1145821001:COnline publication date: 27-Jun-2024
  • (2023)Types and Semantics for Extensible Data TypesProgramming Languages and Systems10.1007/978-981-99-8311-7_3(46-66)Online publication date: 26-Nov-2023
  • (2023)System with Context-free Session TypesProgramming Languages and Systems10.1007/978-3-031-30044-8_15(392-420)Online publication date: 22-Apr-2023
  • (2019)Unraveling Recursion: Compiling an IR with Recursion to System FMathematics of Program Construction10.1007/978-3-030-33636-3_15(414-443)Online publication date: 20-Oct-2019
  • (2019)System F in Agda, for Fun and ProfitMathematics of Program Construction10.1007/978-3-030-33636-3_10(255-297)Online publication date: 20-Oct-2019
  • (2021)On the semantic expressiveness of recursive typesProceedings of the ACM on Programming Languages10.1145/34343025:POPL(1-29)Online publication date: 4-Jan-2021

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media