skip to main content
research-article
Open Access
Artifacts Evaluated & Functional

Decomposition diversity with symmetric data and codata

Published:20 December 2019Publication History
Skip Abstract Section

Abstract

The expression problem describes a fundamental trade-off in program design: Should a program's primary decomposition be determined by the way its domain objects are constructed ("functional" decomposition), or by the way they are destructed ("object-oriented" decomposition)? We argue that programming languages should not force one of these decompositions on the programmer; rather, a programming language should support both ways of decomposing a program in a symmetric way, with an easy translation between these decompositions. However, current programming languages are usually not symmetric and hence make it unnecessarily hard to switch the decomposition.

We propose a language that is symmetric in this regard and allows a fully automatic translation between "functional" and "object-oriented" decomposition. We present a language with algebraic data types and pattern matching for "functional" decomposition and codata types and copattern matching for "object-oriented" decomposition, together with a bijective translation that turns a data type into a codata type ("destructorization") or vice versa ("constructorization"). We present the first symmetric programming language with support for local (co)pattern matching, which includes local anonymous function or object definitions, that allows an automatic translation as described above. We also present the first mechanical formalization of such a language and prove i) that the type system is sound, that the translations between data and codata types are ii) type-preserving, iii) behavior-preserving and iv) inverses of each other. We also extract a mechanically verified implementation from our formalization and have implemented an IDE with direct support for these translations.

Skip Supplemental Material Section

Supplemental Material

a30-binder.webm

References

  1. Andreas Abel, Brigitte Pientka, David Thibodeau, and Anton Setzer. 2013. Copatterns: Programming infinite structures by observations. In Proceedings of the Symposium on Principles of Programming Languages. ACM, 27–38.Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Robert Atkey and Conor McBride. 2013. Productive Coprogramming with Guarded Recursion. In Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming (ICFP ’13). ACM, New York, NY, USA, 197–208.Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. David Baelde. 2012. Least and Greatest Fixed Points in Linear Logic. ACM Trans. Comput. Logic 13, 1, Article 2 (Jan. 2012), 2:1–2:44 pages.Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Henk Barendregt. 1991. Introduction to generalized type systems. Journal of functional programming 1, 2 (1991), 125–154.Google ScholarGoogle ScholarCross RefCross Ref
  5. Urban Boquist and Thomas Johnsson. 1996. The GRIN project: A highly optimising back end for lazy functional languages. In Symposium on Implementation and Application of Functional Languages. Springer, 58–84.Google ScholarGoogle Scholar
  6. Jacques Carette, Oleg Kiselyov, and Chung-Chieh Shan. 2007. Finally tagless, partially evaluated. In Proceedings of the Asian Symposium on Programming Languages and Systems. Springer LNCS 4807, 222–238. Google ScholarGoogle ScholarCross RefCross Ref
  7. William R. Cook. 1990. Object-oriented programming versus abstract data types. In Proceedings of the REX Workshop / School on the Foundations of Object-Oriented Languages. Springer-Verlag, 151–178.Google ScholarGoogle Scholar
  8. William R. Cook. 2009. On understanding data abstraction, revisited. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications. ACM, 557–572.Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Olivier Danvy, Jacob Johannsen, and Ian Zerny. 2011. A walk in the semantic park. In Proceedings of the 20th ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM ’11). ACM, New York, NY, USA, 1–12.Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Olivier Danvy and Kevin Millikin. 2009. Refunctionalization at work. Science of Computer Programming 74, 8 (2009), 534–549.Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Olivier Danvy and Lasse R. Nielsen. 2001. Defunctionalization at work. In Proceedings of the Conference on Principles and Practice of Declarative Programming. 162–174.Google ScholarGoogle Scholar
  12. Paul Downen, Zachary Sullivan, Zena M Ariola, and Simon Peyton Jones. 2019. Codata in Action. In European Symposium on Programming. Springer, 119–146.Google ScholarGoogle Scholar
  13. Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. 1995. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Publishing Co., Boston, Massachusetts, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Eduardo Giménez. 1996. An application of co-inductive types in Coq: Verification of the alternating bit protocol. In Types for Proofs and Programs, Stefano Berardi and Mario Coppo (Eds.). Springer Berlin Heidelberg.Google ScholarGoogle Scholar
  15. Torsten Grust, Nils Schweinsberg, and Alexander Ulrich. 2013. Functions are data too: defunctionalization for PL/SQL. Proceedings of the VLDB Endowment 6, 12 (2013), 1214–1217.Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Tatsuya Hagino. 1989. Codatatypes in ML. Journal of Symbolic Computation 8, 6 (1989), 629–650.Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Bart Jacobs. 1995. Objects and classes, coalgebraically. In Object Orientation with Parallelism and Persistence. Springer-Verlag, 83–103.Google ScholarGoogle Scholar
  18. Thomas Johnsson. 1985. Lambda lifting: Transforming programs to recursive equations. In Functional Programming Languages and Computer Architecture, Jean-Pierre Jouannaud (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg, 190–203.Google ScholarGoogle Scholar
  19. Shriram Krishnamurthi, Matthias Felleisen, and Daniel P. Friedman. 1998. Synthesizing Object-Oriented and Functional Design to Promote Re-Use. In Proceedings of the 12th European Conference on Object-Oriented Programming (ECCOP ’98). Springer-Verlag, Berlin, Heidelberg, 91–113. http://dl.acm.org/citation.cfm?id=646155.679709Google ScholarGoogle Scholar
  20. Paul Laforgue and Yann Régis-Gianas. 2017. Copattern Matching and First-class Observations in OCaml, with a Macro. In Proceedings of the 19th International Symposium on Principles and Practice of Declarative Programming (PPDP ’17). ACM, New York, NY, USA.Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Ralf Lämmel and Ondrej Rypacek. 2008. The Expression Lemma. In Proceedings of the Conference on Mathematics of Program Construction. Springer LNCS 5133.Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Bruno C. d. S. Oliveira and William R. Cook. 2012. Extensibility for the Masses: Practical Extensibility with Object Algebras. In Proceedings of the 26th European Conference on Object-Oriented Programming (ECOOP’12). Springer-Verlag, Berlin, Heidelberg, 2–27.Google ScholarGoogle Scholar
  23. Klaus Ostermann and Julian Jabs. 2018. Dualizing Generalized Algebraic Data Types by Matrix Transposition. In European Symposium on Programming. Springer, 60–85.Google ScholarGoogle ScholarCross RefCross Ref
  24. Tillmann Rendel, Julia Trieflinger, and Klaus Ostermann. 2015. Automatic refunctionalization to a language with copattern matching: With applications to the expression problem. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming (ICFP 2015). ACM, New York, NY, USA, 269–279.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. John C. Reynolds. 1972. Definitional interpreters for higher-order programming languages. In Proceedings of the ACM annual conference. ACM, 717–740.Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. John C. Reynolds. 1975. User-defined types and procedural data structures as complementary approaches to data abstraction. In New Directions in Algorithmic Languages 1975, Stephen Schuman (Ed.). IFIP Working Group 2.1 on Algol, INRIA, Rocquencourt, France, 157–168.Google ScholarGoogle Scholar
  27. Philip Wadler. 1998. The Expression Problem. (Nov. 1998). Note to Java Genericity mailing list.Google ScholarGoogle Scholar
  28. Philip Wadler. 2003. Call-by-value is dual to call-by-name. In Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming (ICFP ’03). ACM, New York, NY, USA, 189–201.Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Noam Zeilberger. 2008. On the unity of duality. Annals of Pure and Applied Logic 153, 1-3 (2008), 66–96.Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. Decomposition diversity with symmetric data and codata

          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

          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!