Type-safe compilation of covariant specialization: A practical case

  • John Boyland
  • Giuseppe Castagna
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 1098)


Despite its lack of type safety, some typed object-oriented languages use covariant specialization for methods. In this work, we show how one may modify the semantics of languages that use covariant specialization in order to improve their type safety. We demonstrate our technique using O2, a strongly and statically typed object-oriented database programming language which uses covariant specialization. We propose a modification to the O2 compiler that adds code to correct previously ill-typed computations that arise from the use of covariant specialization. The modification we propose does not affect the semantics of those computations without type errors. Furthermore, the new semantics of the previously ill-typed computations is defined in a very “natural” way and ensures the type safety (w.r.t. covariance) of the program. Since the solution consists of a conservative backward-compatible modification of the compiler, it does not require, unlike other solutions, any modification of existing O2 code. Our solution is based solely on a type-theoretic analysis and thus is general. Therefore, although this paper applies it to a particular programming language, the same ideas could easily be applied to other languages that use covariant specialization.


Static Class Type Error Arbitrary Choice Covariant Specialization Class Point 
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.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [ABDS96]
    E. Amiel, M.-J. Bellosta, E. Dujardin, and E. Simon. Type-safe relaxing of schema consistency rules for flexible modelling in OODBMS. Very Large Databases Journal, 5(2):108–119, April 1996.Google Scholar
  2. [ADL91]
    R. Agrawal, L. DeMichiel, and B. Lindsay. Static type checking of multi-methods. ACM SIGPLAN Notices, 26(11):113–128, 1991. Proceedings of OOPSLA'91.CrossRefGoogle Scholar
  3. [BCC+96]
    K. Bruce, L. Cardelli, G. Castagna, The Hopkins Object Group, G. Leavens, and B. Pierce. On binary methods. Theory and Practice of Object Systems, 1(3), 1996.Google Scholar
  4. [BDK92]
    F. Bancilhon, C. Delobel, and P. Kanellakis, editors. Implementing an Object-Oriented Database System: The Story of O 2. Morgan Kaufmann, 1992.Google Scholar
  5. [BG96]
    M. F. Barrett and M. E. Giguere. A note on covariance and contravariance unification. ACM SIGPLAN Notices, 31(1):32–35, Jan. 1996.CrossRefGoogle Scholar
  6. [BHJL86]
    A. Black, N. Hutchinson, E. Jul, and H. Levy. Object structure in the Emerald system. In Norman Meyrowitz, editor, OOPSLA '86 Conference Proceedings, volume 21(11) of SIGPLAN Notices, pages 347–349, Nov. 1986.Google Scholar
  7. [Bru94]
    K.B. Bruce. A paradigmatic object-oriented programming language: Design, static typing and semantics. Journal of Functional Programming, 4(2):127–206, 1994.zbMATHCrossRefMathSciNetGoogle Scholar
  8. [Car88]
    L. Cardelli. A semantics of multiple inheritance. Information and Computation, 76:138–164, 1988. A previous version can be found in Semantics of Data Types, LNCS 173, 51–67, Springer-Verlag, 1984.zbMATHMathSciNetCrossRefGoogle Scholar
  9. [Cas95a]
    G. Castagna. Covariance and contravariance: conflict without a cause. ACM Transactions on Programming Languages and Systems, 17(3):431–447, 1995.CrossRefGoogle Scholar
  10. [Cas95b]
    G. Castagna. A meta-language for typed object-oriented languages. Theoretical Computer Science, 151(2):297–352, Nov. 1995.zbMATHMathSciNetCrossRefGoogle Scholar
  11. [Cas96]
    G. Castagna. Object-Oriented Programming: A Unified Foundation. Progress in Theoretical Computer Science. Birkäuser, Boston, 1996.Google Scholar
  12. [CGL95]
    G. Castagna, G. Ghelli, and G. Longo. A calculus for overloaded functions with subtyping. Information and Computation, 117(1):115–135, 1995, A preliminary version was presented at the 1992 ACM Conference on LISP and Functional Programming, San Francisco, June 1992.MathSciNetCrossRefzbMATHGoogle Scholar
  13. [CL95]
    C. Chambers and G. Leavens. Typechecking and modules for multi-methods. ACM Transactions on Programming Languages and Systems, 17(6):805–843, Nov. 1995.CrossRefGoogle Scholar
  14. [Coo91]
    W. Cook. Object-oriented programming versus abstract data types. In J. W. de Bakker, W. P. de Roever, and G. Rozenberg, editors, Foundations of Object-Oriented Languages, REX School/Workshop, volume 489 of LNCS, pages 151–178. Springer-Verlag, 1991.Google Scholar
  15. [DG87]
    L.G. DeMichiel and R.P. Gabriel. Common Lisp Object System overview. In Bézivin, Hullot, Cointe, and Lieberman, editors, ECOOP '87 Conference Proceedings, volume 276 of LNCS, pages 151–170. Springer-Verlag, 1987.Google Scholar
  16. [GR83]
    A. Goldberg and D. Robson. Smalltalk-80: The Language and Its Implementation. Addison-Wesley, Reading, Mass., 1983.zbMATHGoogle Scholar
  17. [Ing86]
    D. H. H. Ingalls. A simple technique for handling multiple polymorphism. In Norman Meyrowitz, editor, OOPSLA '86 Conference Proceedings, volume 21(11) of SIGPLAN Notices, pages 347–349, Nov. 1986.Google Scholar
  18. [Mey91]
    Bertrand Meyer. Eiffel: The Language. Prentice-Hall, 1991.Google Scholar
  19. [Mey96]
    Bertrand Meyer. Object-Oriented Software Construction. Prentice-Hall, 2nd edition, to appear 1996.Google Scholar
  20. [MHH91]
    W. B. Mugridge, J. G. Hosking, and J. Hamer. Multi-methods in a statically-typed programming language. In P. America, editor, ECOOP '91 Conference Proceedings, volume 512 of LNCS, pages 307–324. Springer-Verlag, 1991.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1996

Authors and Affiliations

  • John Boyland
    • 1
  • Giuseppe Castagna
    • 2
  1. 1.University of California at BerkeleyBerkeleyUSA
  2. 2.école Normale SupérieureCNRS, LIENS-DMIParisFrance

Personalised recommendations