Abstract
Defunctionalization 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-order functions. To remedy this asymmetry, we generalize from first-class functions to arbitrary codata. This leads us to full defunctionalization and refunctionalization between a codata language based on copattern matching and a data language based on pattern matching. We observe how programs can be written as matrices so that they are modularly extensible in one dimension but not the other. In this representation, defunctionalization and refunctionalization correspond to matrix transposition which effectively changes the dimension of extensibility a program supports. This suggests applications to the expression problem.
- A. Abel, B. Pientka, D. Thibodeau, and A. Setzer. Copatterns: Programming infinite structures by observations. In Proceedings of the Symposium on Principles of Programming Languages, pages 27–38. ACM, 2013. Google Scholar
Digital Library
- M. S. Ager, D. Biernacki, O. Danvy, and J. Midtgaard. A functional correspondence between evaluators and abstract machines. In Proceedings of the Conference on Principles and Practice of Declarative Programming, pages 8–19. ACM, 2003. Google Scholar
Digital Library
- U. B. Berger and H. Schwichtenberg. An inverse of the evaluation functional for typed λ–calculus. In Proceedings of the Symposium on Logic in Computer Science, pages 203–211. IEEE Computer Society, 1991.Google Scholar
- J. Carette, O. Kiselyov, and C. Shan. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming, 19(5):509–543, Sept. 2009. Google Scholar
Digital Library
- W. R. Cook. Object-oriented programming versus abstract data types. In Proceedings of the REX Workshop / School on the Foundations of Object-Oriented Languages, pages 151–178. Springer-Verlag, 1990. Google Scholar
Digital Library
- W. R. Cook. On understanding data abstraction, revisited. In Proceedings of the Conference on Object-Oriented Programming, Systems, Languages and Applications, pages 557–572. ACM, 2009. Google Scholar
Digital Library
- O. Danvy and K. Millikin. Refunctionalization at work. Science of Computer Programming, 74(8):534–549, 2009. Google Scholar
Digital Library
- O. Danvy and L. R. Nielsen. Defunctionalization at work. In Proceedings of the Conference on Principles and Practice of Declarative Programming, pages 162–174, 2001. Google Scholar
Digital Library
- P. Hudak. Modular domain specific languages and tools. In Proceedings of the Conference on Software Reuse, pages 134–142. IEEE Computer Society, June 1998. Google Scholar
Digital Library
- D. Janzen and K. de Volder. Programming with crosscutting effective views. In Proceedings of the European Conference on Object-Oriented Programming, pages 195–218. Springer LNCS 3086, 2004.Google Scholar
- R. Lämmel and O. Rypacek. The Expression Lemma. In Proceedings of the Conference on Mathematics of Program Construction. Springer LNCS 5133, July 2008. Google Scholar
Digital Library
- F. Pottier and N. Gauthier. Polymorphic typed defunctionalization and concretization. Higher-Order and Symbolic Computation, 19(1):125– 162, Mar. 2006. Google Scholar
Digital Library
- J. C. Reynolds. Definitional interpreters for higher-order programming languages. In Proceedings of the ACM annual conference, pages 717– 740. ACM, 1972. Google Scholar
Digital Library
- J. C. Reynolds. User-defined types and procedural data structures as complementary approaches to data abstraction. In New Directions in Algorithmic Languages 1975, pages 157–168. IFIP Working Group 2.1 on Algol, INRIA, 1975.Google Scholar
- A. Setzer, A. Abel, B. Pientka, and D. Thibodeau. Unnesting of copatterns. In Proceedings of the Joint Conference on Rewriting Techniques and Applications and Typed Lambda Calculi and Applications, pages 31–45. Springer LNCS 8560, 2014.Google Scholar
- P. Wadler. The expression problem. Note to Java Genericity mailing list, Nov. 1998.Google Scholar
Index Terms
Automatic refunctionalization to a language with copattern matching: with applications to the expression problem
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-...
Refunctionalization at work
We present the left inverse of Reynolds' defunctionalization and we show its relevance to programming and to programming languages. We propose two methods to transform a program that is almost in defunctionalized form into one that is actually in ...
Decomposition diversity with symmetric data and codata
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-...






Comments