Skip to main content

Extensibility for the Masses

Practical Extensibility with Object Algebras

  • Conference paper

Part of the book series: Lecture Notes in Computer Science ((LNPSE,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.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Bierman, G.M., Meijer, E., Torgersen, M.: Lost in translation: formalizing proposed extensions to C#. In: OOPSLA 2007 (2007)

    Google Scholar 

  2. Bracha, G., Cook, W.: Mixin-based inheritance. In: OOPSLA/ECOOP 1990 (1990)

    Google Scholar 

  3. Bruce, K.: Some challenging typing issues in object-oriented languages: Extended abstract. Electronic Notes in Theoretical Computer Science 82(8), 1–29 (2003)

    Article  Google Scholar 

  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)

    Chapter  Google Scholar 

  5. Buchlovsky, P., Thielecke, H.: A type-theoretic reconstruction of the visitor pattern. Electronic Notes in Theoretical Computer Science 155(0), 309–329 (2006)

    Article  Google Scholar 

  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. 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)

    Article  MathSciNet  MATH  Google Scholar 

  8. Chambers, C., Leavens, G.T.: Typechecking and modules for multimethods. ACM Trans. Program. Lang. Syst. 17, 805–843 (1995)

    Article  Google Scholar 

  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. 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)

    Chapter  Google Scholar 

  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. Ernst, E.: Family Polymorphism. In: Lee, S.H. (ed.) ECOOP 2001. LNCS, vol. 2072, pp. 303–326. Springer, Heidelberg (2001)

    Chapter  Google Scholar 

  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. Garrigue, J.: Programming with polymorphic variants (1998)

    Google Scholar 

  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)

    Chapter  Google Scholar 

  16. Gibbons, J.: Design patterns as higher-order datatype-generic programs. In: WGP 2006 (2006)

    Google Scholar 

  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. Guttag, J.V., Horning, J.J.: The algebraic specification of abstract data types. Acta Informatica (1978)

    Google Scholar 

  19. Hinze, R.: Generics for the masses. Journal of Functional Programming 16(4-5), 451–483 (2006)

    Article  MathSciNet  MATH  Google Scholar 

  20. Hofer, C., Ostermann, K., Rendel, T., Moors, A.: Polymorphic embedding of DSLs. In: GPCE 2008 (2008)

    Google Scholar 

  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)

    Chapter  Google Scholar 

  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)

    Chapter  Google Scholar 

  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)

    Chapter  Google Scholar 

  24. Löh, A., Hinze, R.: Open data types and open functions. In: PPDP 2006 (2006)

    Google Scholar 

  25. Madsen, O.L., Moller-Pedersen, B.: Virtual classes: a powerful mechanism in object-oriented programming. In: OOPSLA 1989 (1989)

    Google Scholar 

  26. Malcolm, G.: Algebraic Data Types and Program Transformation. Ph.D. thesis, Rijksuniversiteit Groningen (September 1990)

    Google Scholar 

  27. McDirmid, S., Flatt, M., Hsieh, W.C.: Jiazzi: new-age components for old-fashioned java. In: OOPSLA 2001 (2001)

    Google Scholar 

  28. Moors, A., Piessens, F., Odersky, M.: Generics of a higher kind. In: OOPSLA 2008 (2008)

    Google Scholar 

  29. Nystrom, N., Qi, X., Myers, A.C.: J&: nested intersection for scalable software composition. In: OOPSLA 2006 (2006)

    Google Scholar 

  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. Oliveira, B.C.d.S.: Modular Visitor Components. In: Drossopoulou, S. (ed.) ECOOP 2009. LNCS, vol. 5653, pp. 269–293. Springer, Heidelberg (2009)

    Chapter  Google Scholar 

  32. Oliveira, B.C.d.S., Gibbons, J.: Typecase: a design pattern for type-indexed functions. In: Haskell 2005 (2005)

    Google Scholar 

  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. Oliveira, B.C.d.S., Moors, A., Odersky, M.: Type classes as objects and implicits. In: OOPSLA 2010 (2010)

    Google Scholar 

  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. Palsberg, J., Jay, C.B.: The essence of the visitor pattern. In: COMPSAC 1998 (1998)

    Google Scholar 

  37. Peyton Jones, S., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. In: ICFP 2006 (2006)

    Google Scholar 

  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. Reynolds, J.C.: Towards a Theory of Type Structure. In: Robinet, B. (ed.) Programming Symposium. LNCS, vol. 19, pp. 408–425. Springer, Heidelberg (1974)

    Chapter  Google Scholar 

  40. Saito, C., Igarashi, A.: The essence of lightweight family polymorphism. Journal of Object Technology, 67–99 (2008)

    Google Scholar 

  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)

    Chapter  Google Scholar 

  42. Swierstra, W.: Data types à la carte. Journal of Functional Programming 18(4), 423–436 (2008)

    Article  MathSciNet  MATH  Google Scholar 

  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)

    Chapter  Google Scholar 

  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. Visser, J.: Visitor combination and traversal control. In: OOPSLA 2001 (2001)

    Google Scholar 

  46. Wadler, P.: The Expression Problem. Email (November 1998), discussion on the Java Genericity mailing list

    Google Scholar 

  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. 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. Zenger, M., Odersky, M.: Extensible algebraic datatypes with defaults. In: ICFP 2001 (2001)

    Google Scholar 

  50. Zenger, M., Odersky, M.: Independently extensible solutions to the expression problem. In: FOOL 2005 (2005)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2012 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Oliveira, B.C.d.S., Cook, W.R. (2012). Extensibility for the Masses. In: Noble, J. (eds) ECOOP 2012 – Object-Oriented Programming. ECOOP 2012. Lecture Notes in Computer Science, vol 7313. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-31057-7_2

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-31057-7_2

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-31056-0

  • Online ISBN: 978-3-642-31057-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics