Lazy Contract Checking for Immutable Data Structures

  • Robert Bruce Findler
  • Shu-yu Guo
  • Anne Rogers
Part of the Lecture Notes in Computer Science book series (LNCS, volume 5083)

Abstract

Existing contract checkers for data structures force programmers to choose between poor alternatives. Contracts are either built into the functions that construct the data structure, meaning that each object can only be used with a single contract and that a data structure with an invariant cannot be viewed as a subtype of the data structure without the invariant (thus inhibiting abstraction) or contracts are checked eagerly when an operation on the data structure is invoked, meaning that many redundant checks are performed, potentially even changing the program’s asymptotic complexity.

We explore the idea of adding a small, controlled amount of laziness to contract checkers so that the contracts on a data structure are only checked as the program inspects the data structure. Unlike contracts on the constructors, our lazy contracts allow subtyping and thus preserve the potential for abstraction. Unlike eagerly-checked contracts, our contracts do not affect the asymptotic behavior of the program.

This paper presents our implementation of these ideas, an optimization in our implementation, performance measurements, and a discussion of an extension to our implementation that admits more expressive contracts by loosening the strict asymptotic guarantees and only preserving the amortized asymptotic complexity.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    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
  2. 2.
    Chitil, O., Huch, F.: A pattern logic for prompt lazy assertions. In: Horváth, Z., Zsók, V., Butterfield, A. (eds.) IFL 2006. LNCS, vol. 4449, pp. 126–144. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  3. 3.
    Chitil, O., Huch, F.: Monadic prompt lazy assertions in Haskell. In: Asian Symposium on Programming Languages and Systems (2007)Google Scholar
  4. 4.
    Chitil, O., McNeill, D., Runciman, C.: Lazy assertions. In: Trinder, P., Michaelson, G.J., Peña, R. (eds.) IFL 2003. LNCS, vol. 3145, pp. 1–19. Springer, Heidelberg (2004)Google Scholar
  5. 5.
    Conway, D., Goebel, C.G.: Class: Contract – design-by-contract OO in Perl, http://search.cpan.org/~ggoebel/Class-Contract-1.14/
  6. 6.
    Cormen, T.H., Leiserson, C.E., Rivest, R.L.: Introduction to Algorithms. MIT Press, Cambridge (1990)Google Scholar
  7. 7.
    Felleisen, M., Findler, R.B., Flatt, M., Krishnamurthi, S.: How to Design Programs. MIT Press, Cambridge (2001), http://www.htdp.org/ MATHGoogle Scholar
  8. 8.
    Felzenszwalb, P., McAllester, D.: A min-cover approach for finding salient curves. In: IEEE Workshop on Perceptual Organization in Computer Vision (2006), http://people.cs.uchicago.edu/~pff/papers/
  9. 9.
    Findler, Barzilay, Blume, Codik, Felleisen, Flatt, Huang, Matthews, McCarthy, Scott, Press, Rainey, Reppy, Riehl, Spiro, Tucker, Wick: In: The eighth annual ICFP programming contest, http://icfpc.plt-scheme.org/
  10. 10.
    Findler, R.B., Blume, M.: Contracts as pairs of projections. In: International Symposium on Functional and Logic Programming, pp. 226–241 (2006)Google Scholar
  11. 11.
    Findler, R.B., Felleisen, M.: Contracts for higher-order functions. In: Proceedings of ACM SIGPLAN International Conference on Functional Programming, pp. 48–59 (2002)Google Scholar
  12. 12.
    Flanagan, C., Sabry, A., Duba, B., Felleisen, M.: The essence of compiling with continuations. In: Proceedings of ACM SIGPLAN Conference on Programming Language Design and Implementation (1993)Google Scholar
  13. 13.
    Flatt, M.: PLT MzScheme: Language manual. Technical Report PLT- TR05-1-v300, PLT Scheme Inc. (2005), http://www.plt-scheme.org/techreports/
  14. 14.
    Hinze, R., Jeuring, J., Löh, A.: Typed contracts for functional programming. In: International Symposium on Functional and Logic Programming (2006)Google Scholar
  15. 15.
    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. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  16. 16.
    Meyer, B.: Eiffel: The Language. Prentice Hall, Englewood Cliffs (1992)MATHGoogle Scholar
  17. 17.
    Okasaki, C.: Purely Functional Data Structures. PhD thesis, Carnegie Mellon University, Technical Report CMU-CS-96-177 (September 1996)Google Scholar
  18. 18.
    Okasaki, C.: Purely Functional Data Structures. Cambridge University Press, Cambridge (1999)MATHGoogle Scholar
  19. 19.
    Parnas, D.L.: A technique for software module specification with examples. Communications of the ACM 15(5), 330–336 (1972)CrossRefGoogle Scholar
  20. 20.
    Plösch, R.: Design by contract for Python. In: IEEE Proceedings of the Joint Asia Pacific Software Engineering Conference (1997), http://citeseer.nj.nec.com/257710.html
  21. 21.
    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
  22. 22.
    PLT. PLT MzLib: Libraries manual. Technical Report PLT-TR2007-4-v372, PLT Scheme Inc. (2007), http://www.plt-scheme.org/techreports/
  23. 23.
    Rosenblum, D.S.: A practical approach to programming with assertions. IEEE Transactions on Software Engineering 21(1), 19–31 (1995)CrossRefGoogle Scholar
  24. 24.
    Tremblay, J.-P., Chesterton, G.A.: Data Structures and Software Development in an Object-Oriented Domain: Eiffel Edition. Prentice Hall, Englewood Cliffs (2001)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2008

Authors and Affiliations

  • Robert Bruce Findler
    • 1
  • Shu-yu Guo
    • 1
  • Anne Rogers
    • 1
  1. 1.University of Chicago 

Personalised recommendations