Advertisement

Extensibility for the Masses

Practical Extensibility with Object Algebras
  • Bruno C. d. S. Oliveira
  • William R. Cook
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7313)

Abstract

This paper presents a new solution to the expression problem (EP) that works in OO languages with simple generics (including Java or C#). A key novelty of this solution is that advanced typing features, including F-bounded quantification, wildcards and variance annotations, are not needed. The solution is based on object algebras, which are an abstraction closely related to algebraic datatypes and Church encodings. Object algebras also have much in common with the traditional forms of the Visitor pattern, but without many of its drawbacks: they are extensible, remove the need for accept methods, and do not compromise encapsulation. We show applications of object algebras that go beyond toy examples usually presented in solutions for the expression problem. In the paper we develop an increasingly more complex set of features for a mini-imperative language, and we discuss a real-world application of object algebras in an implementation of remote batches. We believe that object algebras bring extensibility to the masses: object algebras work in mainstream OO languages, and they significantly reduce the conceptual overhead by using only features that are used by everyday programmers.

Keywords

Boolean Expression Algebraic Signature Visitor Pattern Subtyping Relation Expression Problem 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Bierman, G.M., Meijer, E., Torgersen, M.: Lost in translation: formalizing proposed extensions to C#. In: OOPSLA 2007 (2007)Google Scholar
  2. 2.
    Bracha, G., Cook, W.: Mixin-based inheritance. In: OOPSLA/ECOOP 1990 (1990)Google Scholar
  3. 3.
    Bruce, K.: Some challenging typing issues in object-oriented languages: Extended abstract. Electronic Notes in Theoretical Computer Science 82(8), 1–29 (2003)CrossRefGoogle Scholar
  4. 4.
    Bruce, K.B., Odersky, M., Wadler, P.: A Statically Safe Alternative to Virtual Types. In: Jul, E. (ed.) ECOOP 1998. LNCS, vol. 1445, pp. 523–549. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  5. 5.
    Buchlovsky, P., Thielecke, H.: A type-theoretic reconstruction of the visitor pattern. Electronic Notes in Theoretical Computer Science 155(0), 309–329 (2006)CrossRefGoogle Scholar
  6. 6.
    Canning, P., Cook, W., Hill, W., Olthoff, W., Mitchell, J.C.: F-bounded polymorphism for object-oriented programming. In: FPCA 1989 (1989)Google Scholar
  7. 7.
    Carette, J., Kiselyov, O., Shan, C.C.: Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program. 19, 509–543 (2009)MathSciNetzbMATHCrossRefGoogle Scholar
  8. 8.
    Chambers, C., Leavens, G.T.: Typechecking and modules for multimethods. ACM Trans. Program. Lang. Syst. 17, 805–843 (1995)CrossRefGoogle Scholar
  9. 9.
    Clifton, C., Leavens, G.T., Chambers, C., Millstein, T.: MultiJava: modular open classes and symmetric multiple dispatch for java. In: OOPSLA 2000 (2000)Google Scholar
  10. 10.
    Cook, W.R.: Object-Oriented Programming Versus Abstract Data Types. In: de Bakker, J.W., Rozenberg, G., de Roever, W.-P. (eds.) REX 1990. LNCS, vol. 489, pp. 151–178. Springer, Heidelberg (1991)CrossRefGoogle Scholar
  11. 11.
    Duponcheel, L.: Using catamorphisms, subtypes and monad transformers for writing modular functional interpreters (1995), http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.7093
  12. 12.
    Ernst, E.: Family Polymorphism. In: Lee, S.H. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 303–326. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  13. 13.
    Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addisson-Wesley professional computing series. Addisson-Wesley (1994)Google Scholar
  14. 14.
    Garrigue, J.: Programming with polymorphic variants (1998)Google Scholar
  15. 15.
    Ghani, N., Uustalu, T., Vene, V.: Build, Augment and Destroy, Universally. In: Chin, W.-N. (ed.) APLAS 2004. LNCS, vol. 3302, pp. 327–347. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  16. 16.
    Gibbons, J.: Design patterns as higher-order datatype-generic programs. In: WGP 2006 (2006)Google Scholar
  17. 17.
    Girard, J.-Y., Lafont, Y., Taylor, P.: Proofs and Types. Cambridge Tracts in Theoretical Computer Science, vol. 7. Cambridge University Press (1989)Google Scholar
  18. 18.
    Guttag, J.V., Horning, J.J.: The algebraic specification of abstract data types. Acta Informatica (1978)Google Scholar
  19. 19.
    Hinze, R.: Generics for the masses. Journal of Functional Programming 16(4-5), 451–483 (2006)MathSciNetzbMATHCrossRefGoogle Scholar
  20. 20.
    Hofer, C., Ostermann, K., Rendel, T., Moors, A.: Polymorphic embedding of DSLs. In: GPCE 2008 (2008)Google Scholar
  21. 21.
    Hoogendijk, P., Backhouse, R.: When Do Datatypes Commute? In: Moggi, E., Rosolini, G. (eds.) CTCS 1997. LNCS, vol. 1290, pp. 242–260. Springer, Heidelberg (1997)CrossRefGoogle Scholar
  22. 22.
    Ibrahim, A., Jiao, Y., Tilevich, E., Cook, W.R.: Remote Batch Invocation for Compositional Object Services. In: Drossopoulou, S. (ed.) ECOOP 2009. LNCS, vol. 5653, pp. 595–617. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  23. 23.
    Krishnamurthi, S., Felleisen, M., Friedman, D.P.: Synthesizing Object-Oriented and Functional Design to Promote Re-Use. In: Jul, E. (ed.) ECOOP 1998. LNCS, vol. 1445, pp. 91–113. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  24. 24.
    Löh, A., Hinze, R.: Open data types and open functions. In: PPDP 2006 (2006)Google Scholar
  25. 25.
    Madsen, O.L., Moller-Pedersen, B.: Virtual classes: a powerful mechanism in object-oriented programming. In: OOPSLA 1989 (1989)Google Scholar
  26. 26.
    Malcolm, G.: Algebraic Data Types and Program Transformation. Ph.D. thesis, Rijksuniversiteit Groningen (September 1990)Google Scholar
  27. 27.
    McDirmid, S., Flatt, M., Hsieh, W.C.: Jiazzi: new-age components for old-fashioned java. In: OOPSLA 2001 (2001)Google Scholar
  28. 28.
    Moors, A., Piessens, F., Odersky, M.: Generics of a higher kind. In: OOPSLA 2008 (2008)Google Scholar
  29. 29.
    Nystrom, N., Qi, X., Myers, A.C.: J&: nested intersection for scalable software composition. In: OOPSLA 2006 (2006)Google Scholar
  30. 30.
    Oliveira, B.C.d.S.: Genericity, extensibility and type-safety in the Visitor pattern. Ph.D. thesis, Oxford University Computing Laboratory (2007)Google Scholar
  31. 31.
    Oliveira, B.C.d.S.: Modular Visitor Components. In: Drossopoulou, S. (ed.) ECOOP 2009. LNCS, vol. 5653, pp. 269–293. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  32. 32.
    Oliveira, B.C.d.S., Gibbons, J.: Typecase: a design pattern for type-indexed functions. In: Haskell 2005 (2005)Google Scholar
  33. 33.
    Oliveira, B.C.d.S., Hinze, R., Löh, A.: Extensible and modular generics for the masses. In: Trends in Functional Programming (2006)Google Scholar
  34. 34.
    Oliveira, B.C.d.S., Moors, A., Odersky, M.: Type classes as objects and implicits. In: OOPSLA 2010 (2010)Google Scholar
  35. 35.
    Oliveira, B.C.d.S., Wang, M., Gibbons, J.: The visitor pattern as a reusable, generic, type-safe component. In: OOPSLA 2008 (2008)Google Scholar
  36. 36.
    Palsberg, J., Jay, C.B.: The essence of the visitor pattern. In: COMPSAC 1998 (1998)Google Scholar
  37. 37.
    Peyton Jones, S., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. In: ICFP 2006 (2006)Google Scholar
  38. 38.
    Reynolds, J.C.: User-defined types and procedural data structures as complementary approaches to type abstraction. In: Schuman, S.A. (ed.) New Directions in Algorithmic Languages, pp. 157–168 (1975)Google Scholar
  39. 39.
    Reynolds, J.C.: Towards a Theory of Type Structure. In: Robinet, B. (ed.) Programming Symposium. LNCS, vol. 19, pp. 408–425. Springer, Heidelberg (1974)CrossRefGoogle Scholar
  40. 40.
    Saito, C., Igarashi, A.: The essence of lightweight family polymorphism. Journal of Object Technology, 67–99 (2008)Google Scholar
  41. 41.
    Scharli, N., Ducasse, S., Nierstrasz, O., Black, A.P.: Traits: Composable Units of Behaviour. In: Cardelli, L. (ed.) ECOOP 2003. LNCS, vol. 2743, pp. 248–274. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  42. 42.
    Swierstra, W.: Data types à la carte. Journal of Functional Programming 18(4), 423–436 (2008)MathSciNetzbMATHCrossRefGoogle Scholar
  43. 43.
    Torgersen, M.: The Expression Problem Revisited – Four New Solutions Using Generics. In: Vetta, A. (ed.) ECOOP 2004. LNCS, vol. 3086, pp. 123–146. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  44. 44.
    Torgersen, M., Hansen, C.P., Ernst, E., von der Ahé, P., Bracha, G., Gafter, N.: Adding wildcards to the Java programming language. In: SAC 2004 (2004)Google Scholar
  45. 45.
    Visser, J.: Visitor combination and traversal control. In: OOPSLA 2001 (2001)Google Scholar
  46. 46.
    Wadler, P.: The Expression Problem. Email (November 1998), discussion on the Java Genericity mailing listGoogle Scholar
  47. 47.
    Wehr, S., Thiemann, P.: JavaGI: The interaction of type classes with interfaces and inheritance. ACM Trans. Program. Lang. Syst. 33 (July 2011)Google Scholar
  48. 48.
    Wiedermann, B., Cook, W.R.: Remote batch invocation for SQL databases. In: The 13th International Symposium on Database Programming Languages, DBPL (2011)Google Scholar
  49. 49.
    Zenger, M., Odersky, M.: Extensible algebraic datatypes with defaults. In: ICFP 2001 (2001)Google Scholar
  50. 50.
    Zenger, M., Odersky, M.: Independently extensible solutions to the expression problem. In: FOOL 2005 (2005)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Bruno C. d. S. Oliveira
    • 1
  • William R. Cook
    • 2
  1. 1.National University of SingaporeSingapore
  2. 2.University of TexasAustinUSA

Personalised recommendations