The Expression Lemma

  • Ralf Lämmel
  • Ondrej Rypacek
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5133)


Algebraic data types and catamorphisms (folds) play a central role in functional programming as they allow programmers to define recursive data structures and operations on them uniformly by structural recursion. Likewise, in object-oriented (OO) programming, recursive hierarchies of object types with virtual methods play a central role for the same reason. There is a semantical correspondence between these two situations which we reveal and formalize categorically. To this end, we assume a coalgebraic model of OO programming with functional objects. The development may be helpful in deriving refactorings that turn sufficiently disciplined functional programs into OO programs of a designated shape and vice versa.


expression lemma expression problem functional object catamorphism fold the composite design pattern program calculation distributive law free monad cofree comonad 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Awodey, S.: Category Theory. Clarendon Press (2006)Google Scholar
  2. 2.
    Beck, J.: Distributive laws. Lecture Notes in Mathematics 80, 119–140 (1969)CrossRefMathSciNetGoogle Scholar
  3. 3.
    Bierman, G.M., Meijer, E., Torgersen, M.: Lost in translation: formalizing proposed extensions to C#. In: OOPSLA 2007: Proceedings of the 22nd annual ACM SIGPLAN conference on Object oriented programming systems and applications, pp. 479–498. ACM Press, New York (2007)CrossRefGoogle Scholar
  4. 4.
    Birka, A., Ernst, M.D.: A practical type system and language for reference immutability. In: OOPSLA 2004: Proceedings of the 19th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, pp. 35–49. ACM Press, New York (2004)CrossRefGoogle Scholar
  5. 5.
    Chin, W.-N.: Towards an automated tupling strategy. In: PEPM 1993: Proceedings of the 1993 ACM SIGPLAN symposium on Partial evaluation and semantics-based program manipulation, pp. 119–132. ACM Press, New York (1993)CrossRefGoogle Scholar
  6. 6.
    Clarke, D.G., Potter, J.M., Noble, J.: Ownership types for flexible alias protection. In: OOPSLA 1998: Proceedings of the 13th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications, pp. 48–64. ACM Press, New York (1998)CrossRefGoogle Scholar
  7. 7.
    Fiore, M., Plotkin, G., Turi, D.: Abstract Syntax and Variable Binding. In: LICS 1999: Proceedings of the 14th Annual IEEE Symposium on Logic in Computer Science, pp. 193–202. IEEE Press, Los Alamitos (1999)Google Scholar
  8. 8.
    Fisher, K., Reppy, J.: Object-oriented aspects of Moby. Technical report, University of Chicago Computer Science Department Technical Report (TR-2003-10) (July 2003)Google Scholar
  9. 9.
    Fokkinga, M.M.: Tupling and Mutumorphisms. Appeared in: The Squigollist 1(4), 81–82 (1990)Google Scholar
  10. 10.
    Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Reading (1994)Google Scholar
  11. 11.
    Hu, Z., Iwasaki, H., Takeichi, M.: Deriving structural hylomorphisms from recursive definitions. In: ICFP 1996: Proceedings of the first ACM SIGPLAN international conference on Functional programming, pp. 73–82. ACM Press, New York (1996)CrossRefGoogle Scholar
  12. 12.
    Hu, Z., Iwasaki, H., Takeichi, M., Takano, A.: Tupling calculation eliminates multiple data traversals. In: ICFP 1997: Proceedings of the second ACM SIGPLAN international conference on Functional programming, pp. 164–175. ACM Press, New York (1997)CrossRefGoogle Scholar
  13. 13.
    Jacobs, B.: Distributive laws for the coinductive solution of recursive equations. Information and Computation 204(4), 561–587 (2006)zbMATHCrossRefMathSciNetGoogle Scholar
  14. 14.
    Jacobs, B.P.F.: Objects and classes, coalgebraically. In: Freitag, B., Jones, C.B., Lengauer, C., Schek, H.J. (eds.) Object-Orientation with Parallelism and Persistence, pp. 83–103. Kluwer Academic Publishers, Dordrecht (1996)Google Scholar
  15. 15.
    Kabanov, J., Vene, V.: Recursion Schemes for Dynamic Programming. In: Uustalu, T. (ed.) MPC 2006. LNCS, vol. 4014, pp. 235–252. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  16. 16.
    Klin, B.: Adding recursive constructs to bialgebraic semantics. Journal of Logic and Algebraic Programming 60-61, 259–286 (2004)CrossRefMathSciNetGoogle Scholar
  17. 17.
    Launchbury, J., Sheard, T.: Warm fusion: deriving build-catas from recursive definitions. In: FPCA 1995: Proceedings of the seventh international conference on Functional programming languages and computer architecture, pp. 314–323. ACM Press, New York (1995)CrossRefGoogle Scholar
  18. 18.
    Meertens, L.G.L.T.: Paramorphisms. Formal Aspects of Computing 4(5), 413–424 (1992)zbMATHCrossRefGoogle Scholar
  19. 19.
    Meijer, E., Fokkinga, M.M., Paterson, R.: Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)Google Scholar
  20. 20.
    Odersky, M.: The Scala Language Specification, Version 2.6, DRAFT, Programming Methods Laboratory, EPFL, Switzerland (December 19, 2007)Google Scholar
  21. 21.
    Pierce, B.C., Turner, D.N.: Simple type-theoretic foundations for object-oriented programming. Journal of Functional Programming 4(2), 207–247 (1994)zbMATHGoogle Scholar
  22. 22.
    Reichel, H.: An approach to object semantics based on terminal co-algebras. Mathematical Structures in Computer Science 5(2), 129–152 (1995)zbMATHMathSciNetCrossRefGoogle Scholar
  23. 23.
    Rémy, D.: Programming Objects with ML-ART: An extension to ML with Abstract and Record Types. In: Hagiya, M., Mitchell, J.C. (eds.) TACS 1994. LNCS, vol. 789, pp. 321–346. Springer, Heidelberg (1994)Google Scholar
  24. 24.
    Turi, D.: Functorial Operational Semantics and its Denotational Dual. PhD thesis, Free University, Amsterdam (June 1996)Google Scholar
  25. 25.
    Turi, D., Plotkin, G.D.: Towards a mathematical operational semantics. In: Proceedings 12th Annual IEEE Symposium on Logic in Computer Science, LICS 1997, Warsaw, Poland, 29 June – 2 July 1997, pp. 280–291. IEEE Press, Los Alamitos (1997)CrossRefGoogle Scholar
  26. 26.
    Uustalu, T., Vene, V., Pardo, A.: Recursion schemes from comonads. Nordic Journal of Computing 8(3), 366–390 (2001)zbMATHMathSciNetGoogle Scholar
  27. 27.
    Vene, V., Uustalu, T.: Functional programming with apomorphisms (corecursion). Proceedings of the Estonian Academy of Sciences: Physics, Mathematics 47(3), 147–161 (1998)zbMATHMathSciNetGoogle Scholar
  28. 28.
    Wadler, P.: The expression problem. Message to java-genericity electronic mailing list (November 1998),

Copyright information

© Springer-Verlag Berlin Heidelberg 2008

Authors and Affiliations

  • Ralf Lämmel
    • 1
  • Ondrej Rypacek
    • 2
  1. 1.The University of Koblenz-LandauGermany
  2. 2.The University of NottinghamUK

Personalised recommendations