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.
Supplemental Material
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Henk Barendregt. 1991. Introduction to generalized type systems. Journal of functional programming 1, 2 (1991), 125–154.Google Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Olivier Danvy and Kevin Millikin. 2009. Refunctionalization at work. Science of Computer Programming 74, 8 (2009), 534–549.Google Scholar
Digital Library
- 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 Scholar
- Paul Downen, Zachary Sullivan, Zena M Ariola, and Simon Peyton Jones. 2019. Codata in Action. In European Symposium on Programming. Springer, 119–146.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- Tatsuya Hagino. 1989. Codatatypes in ML. Journal of Symbolic Computation 8, 6 (1989), 629–650.Google Scholar
Digital Library
- Bart Jacobs. 1995. Objects and classes, coalgebraically. In Object Orientation with Parallelism and Persistence. Springer-Verlag, 83–103.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Ralf Lämmel and Ondrej Rypacek. 2008. The Expression Lemma. In Proceedings of the Conference on Mathematics of Program Construction. Springer LNCS 5133.Google Scholar
Digital Library
- 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 Scholar
- Klaus Ostermann and Julian Jabs. 2018. Dualizing Generalized Algebraic Data Types by Matrix Transposition. In European Symposium on Programming. Springer, 60–85.Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- John C. Reynolds. 1972. Definitional interpreters for higher-order programming languages. In Proceedings of the ACM annual conference. ACM, 717–740.Google Scholar
Digital Library
- 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 Scholar
- Philip Wadler. 1998. The Expression Problem. (Nov. 1998). Note to Java Genericity mailing list.Google Scholar
- 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 Scholar
Digital Library
- Noam Zeilberger. 2008. On the unity of duality. Annals of Pure and Applied Logic 153, 1-3 (2008), 66–96.Google Scholar
Cross Ref
Index Terms
Decomposition diversity with symmetric data and codata
Recommendations
Automatic refunctionalization to a language with copattern matching: with applications to the expression problem
ICFP 2015: Proceedings of the 20th ACM SIGPLAN International Conference on Functional ProgrammingDefunctionalization and refunctionalization establish a correspondence between first-class functions and pattern matching, but the correspondence is not symmetric: Not all uses of pattern matching can be automatically refunctionalized to uses of higher-...
Automatic refunctionalization to a language with copattern matching: with applications to the expression problem
ICFP '15Defunctionalization and refunctionalization establish a correspondence between first-class functions and pattern matching, but the correspondence is not symmetric: Not all uses of pattern matching can be automatically refunctionalized to uses of higher-...
Undecidability of Equality for Codata Types
Coalgebraic Methods in Computer ScienceAbstractDecidability of type checking for dependently typed languages usually requires a decidable equality on types. Since bisimilarity on (weakly final) coalgebras such as streams is undecidable, one cannot use it as the equality in type checking. ...






Comments