Semantic Casts: Contracts and Structural Subtyping in a Nominal World

  • Robert Bruce Findler
  • Matthew Flatt
  • Matthias Felleisen
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3086)


Nominal subtyping forces programmers to explicitly state all of the subtyping relationships in the program. This limits component reuse, because programmers cannot anticipate all of the contexts in which a particular class might be used. In contrast, structural subtyping implicitly allows any type with appropriate structure to be used in a given context. Languagues with contracts exacerbate the problem. Since contracts are typically expressed as refinements of types, contracts in nominally typed languages introduce additional obstacles to reuse.

To overcome this problem we show how to extend a nominally typed language with semantic casts that introduce a limited form of structural subtyping. The new language must dynamically monitor contracts, as new subtyping relationships are exploited via semantic casts. In addition, it must also track the casts to properly assign blame in case interface contract are violated.


Operational Semantic Typing Rule Type Check Argument Object Contract Violation 
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. 1.
    America, P.: Designing an object-oriented programming language with behavioural subtyping. In: de Bakker, J.W., Rozenberg, G., de Roever, W.-P. (eds.) REX 1990. LNCS, vol. 489, pp. 60–90. Springer, Heidelberg (1991)CrossRefGoogle Scholar
  2. 2.
    Bartetzko, D., Fischer, C., Moller, M., Wehrheim, H.: Jass - Java with assertions. In: Workshop on Runtime Verification, 2001. Held in conjunction with the 13th Conference on Computer Aided Verification, CAV (2001)Google Scholar
  3. 3.
    Bruce, K.B., Fiech, A., Petersen, L.: Subtyping is not a good “match” for object-oriented languages. In: Proceedings of European Conference on Object-Oriented Programming, pp. 104–127 (1997)Google Scholar
  4. 4.
    Bruce, K.B., Schuett, A., van Gent, R.: PolyTOIL:Atype-safe polymorphic object-oriented language. In: Olthoff, W. (ed.) ECOOP 1995. LNCS, vol. 952, pp. 27–51. Springer, Heidelberg (1995)Google Scholar
  5. 5.
    Carrillo-Castellon, M., Garcia-Molina, J., Pimentel, E., Repiso, I.: Design by contract in smalltalk. Journal of Object-Oriented Programming 7(9), 23–28 (1996)Google Scholar
  6. 6.
    Cheon, Y.: A runtime assertion checker for the Java Modelling Language. Technical Report 03-09, Iowa State University Computer Science Department (April 2003)Google Scholar
  7. 7.
    Detlefs, D.L., Rustan, K., Leino, M., Nelson, G., Saxe, J.B.: Extended static checking. Technical Report 158, Compaq SRC Research Report (1998)Google Scholar
  8. 8.
    Duncan, A., Hölzle, U.: Adding contracts to Java with handshake. Technical Report TRCS98-32, The University of California at Santa Barbara (December 1998)Google Scholar
  9. 9.
    Findler, R.B., Clements, J., Flanagan, C., Flatt, M., Krishnamurthi, S., Steckler, P., Felleisen, M.: DrScheme: A programming environment for Scheme. PLILP 1997 12(2), 159–182 (2002); Hartel, P.H., Kuchen, H. (eds.) PLILP 1997. LNCS, vol. 1292, pp. 369–388. Springer, Heidelberg (1997)Google Scholar
  10. 10.
    Findler, R.B., Felleisen, M.: Contract soundness for object-oriented languages. In: Object- Oriented Programming, Systems, Languages, and Applications (2001)Google Scholar
  11. 11.
    Findler, R.B., Felleisen, M.: Contracts for higher-order functions. In: Proceedings of ACM SIGPLAN International Conference on Functional Programming (2002)Google Scholar
  12. 12.
    Findler, R.B., Latendresse, M., Felleisen, M.: Behavioral contracts and behavioral subtyping. In: Proceedings of ACM Conference Foundations of Software Engineering (2001)Google Scholar
  13. 13.
    Fisher, K., Reppy, J.H.: The design of a class mechanism for Moby. In: Proceedings of ACM SIGPLAN Conference on Programming Language Design and Implementation (1999)Google Scholar
  14. 14.
    Flanagan, C., Leino, K.R.M., Lillibridge, M., Nelson, G., Saxe, J.B., Stata, R.: Extended static checking for Java. In: Proceedings of ACM SIGPLAN Conference on Programming Language Design and Implementation, pp. 234–245 (2002)Google Scholar
  15. 15.
    Flatt, M.P.: MzScheme: Language manual. Technical Report TR97-280, Rice University (1997),
  16. 16.
    Flatt, M., Krishnamurthi, S., Felleisen, M.: Classes and mixins. In: Proceedings of the ACM Conference Principles of Programming Languages, Janurary 1998, pp. 171–183 (1998)Google Scholar
  17. 17.
    Gomes, B., Stoutamire, D., Vaysman, B., Klawitter, H.: A Language Manual for Sather 1.1 (August 1996)Google Scholar
  18. 18.
    Gosling, J., Joy, B., Guy Steele, J.: The Java(tm) Language Specification. Addison-Wesley, Reading (1996)Google Scholar
  19. 19.
    Guttag, J.V., Horning, J.J.: Larch: Languages andTools forFormal Specification. Springer, Heidelberg (1993)Google Scholar
  20. 20.
    Henglein, F.: Dynamic typing: Syntax and proof theory. Science of Computer Programming 22(3), 197–230 (1994)zbMATHCrossRefMathSciNetGoogle Scholar
  21. 21.
    Holt, R.C., Cordy, J.R.: The Turing programming language. Communications of the ACM 31, 1310–1423 (1988)CrossRefGoogle Scholar
  22. 22.
    Karaorman, M., Hölzle, U., Bruno, J.: jContractor: A reflective Java library to support design by contract. In: Cointe, P. (ed.) Reflection 1999. LNCS, vol. 1616, p. 175. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  23. 23.
    Kizub, M.: Kiev language specification (1998),
  24. 24.
    Kölling, M., Rosenberg, J.: Blue: Language Specification, version 0.94 (1997)Google Scholar
  25. 25.
    Kramer, R.: iContract: The Java design by contract tool. In: Technology of Object-Oriented Languages and Systems (1998)Google Scholar
  26. 26.
    Lampson, B.W., Horning, J.J., London, R.L., Mitchell, J.G., Popek, G.J.: Report on the programming language Euclid. ACM Sigplan Notices 12(2) (Feburary 1977)Google Scholar
  27. 27.
    Leavens, G.T., Leino, K.R.M., Poll, E., Ruby, C., Jacobs, B.: JML: notations and tools supporting detailed design in Java. In: Object-Oriented Programming, Systems, Languages, and Applications Companion, Also Department of Computer Science, Iowa State University, TR 00-15, August 2000, pp. 105–106 (2000)Google Scholar
  28. 28.
    Leroy, X.: Applicative functors and fully transparent higher-order modules. In: Proceedings of the ACM Conference Principles of Programming Languages, pp. 142–153. ACM Press, New York (1995)Google Scholar
  29. 29.
    Leroy, X.: The Objective Caml system, Documentation and User’s guide (1997)Google Scholar
  30. 30.
    Liskov, B.H., Wing, J.: Behavioral subtyping using invariants and constraints. Technical Report CMU CS-99-156, School of Computer Science, Carnegie Mellon University (July 1999)Google Scholar
  31. 31.
    Luckham, D.C., von Henke, F.: An overview of Anna, a specification language for Ada. IEEE Software 2, 9–23 (1985)CrossRefGoogle Scholar
  32. 32.
    Man Machine Systems. Design by contract for Java using JMSAssert (2000),
  33. 33.
    Meyer, B.: Eiffel: The Language. Prentice Hall, Englewood Cliffs (1992)zbMATHGoogle Scholar
  34. 34.
    Microsoft Corporation. Microsoft C# Language Specifications. Microsoft Press (2001)Google Scholar
  35. 35.
    Milner, R., Tofte, M., Harper, R.: The Definition of Standard ML. MIT Press, Cambridge (1990)Google Scholar
  36. 36.
    Object Management Group. The object management architecture guide (1997),
  37. 37.
    Parnas, D.L.: A technique for software module specification with examples. Communications of the ACM 15(5), 330–336 (1972)CrossRefGoogle Scholar
  38. 38.
    Plösch, R.: Design by contract for Python. In: IEEE Proceedings of the Joint Asia Pacific Software Engineering Conference (1997),
  39. 39.
    Plösch, R., Pichler, J.: Contracts: From analysis to C++ implementation. In: Technology of Object-Oriented Languages and Systems, pp. 248–257 (1999)Google Scholar
  40. 40.
    Rémy, D., Vouillon, J.: Objective ML: A simple object-oriented extension of ML. In: Proceedings of the ACM Conference Principles of Programming Languages, January 1997, pp. 40–53 (1997)Google Scholar
  41. 41.
    Rosenblum, D.S.: A practical approach to programming with assertions. IEEE Transactions on Software Engineering 21(1), 19–31 (1995)CrossRefGoogle Scholar
  42. 42.
    Sannella, D.: Formal program development in Extended ML for the working programmer. In: Proc. 3rd BCS/FACS Workshop on Refinement; Springer Workshops in Computing, pp. 99–130 (1991)Google Scholar
  43. 43.
    Sannella, D., Tarlecki, A.: Essential concepts of algebraic specification and program development. Formal Aspects of Computing 9, 229–269 (1997), zbMATHCrossRefGoogle Scholar
  44. 44.
    Scott, D.S.: Data types as lattices. Society of Industrial and Applied Mathematics (SIAM) Journal of Computing 5(3), 522–586 (1976)zbMATHGoogle Scholar
  45. 45.
    Stroustrup, B.: The C++ Programming Language. Addison-Wesley, Reading (1997)Google Scholar
  46. 46.
    Szyperski, C.: Component Software, 2nd edn. Addison-Wesley, Reading (1998)Google Scholar
  47. 47.
    Wright, A., Felleisen, M.: A syntactic approach to type soundness. Information and Computation, pp. 38–94 (1994); First appeared as Technical Report TR160, Rice University (1991)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2004

Authors and Affiliations

  • Robert Bruce Findler
    • 1
  • Matthew Flatt
    • 2
  • Matthias Felleisen
    • 3
  1. 1.University of ChicagoChicagoUSA
  2. 2.University of Utah SaltLake CityUSA
  3. 3.Northeastern UniversityBostonUSA

Personalised recommendations