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.
Access provided by Autonomous University of Puebla. Download to read the full chapter text
Chapter PDF
Similar content being viewed by others
Keywords
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.
References
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)
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)
Chitil, O., Huch, F.: Monadic prompt lazy assertions in Haskell. In: Asian Symposium on Programming Languages and Systems (2007)
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)
Conway, D., Goebel, C.G.: Class: Contract – design-by-contract OO in Perl, http://search.cpan.org/~ggoebel/Class-Contract-1.14/
Cormen, T.H., Leiserson, C.E., Rivest, R.L.: Introduction to Algorithms. MIT Press, Cambridge (1990)
Felleisen, M., Findler, R.B., Flatt, M., Krishnamurthi, S.: How to Design Programs. MIT Press, Cambridge (2001), http://www.htdp.org/
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/
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/
Findler, R.B., Blume, M.: Contracts as pairs of projections. In: International Symposium on Functional and Logic Programming, pp. 226–241 (2006)
Findler, R.B., Felleisen, M.: Contracts for higher-order functions. In: Proceedings of ACM SIGPLAN International Conference on Functional Programming, pp. 48–59 (2002)
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)
Flatt, M.: PLT MzScheme: Language manual. Technical Report PLT- TR05-1-v300, PLT Scheme Inc. (2005), http://www.plt-scheme.org/techreports/
Hinze, R., Jeuring, J., Löh, A.: Typed contracts for functional programming. In: International Symposium on Functional and Logic Programming (2006)
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)
Meyer, B.: Eiffel: The Language. Prentice Hall, Englewood Cliffs (1992)
Okasaki, C.: Purely Functional Data Structures. PhD thesis, Carnegie Mellon University, Technical Report CMU-CS-96-177 (September 1996)
Okasaki, C.: Purely Functional Data Structures. Cambridge University Press, Cambridge (1999)
Parnas, D.L.: A technique for software module specification with examples. Communications of the ACM 15(5), 330–336 (1972)
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
Plösch, R., Pichler, J.: Contracts: From analysis to C++ implementation. In: Technology of Object-Oriented Languages and Systems, pp. 248–257 (1999)
PLT. PLT MzLib: Libraries manual. Technical Report PLT-TR2007-4-v372, PLT Scheme Inc. (2007), http://www.plt-scheme.org/techreports/
Rosenblum, D.S.: A practical approach to programming with assertions. IEEE Transactions on Software Engineering 21(1), 19–31 (1995)
Tremblay, J.-P., Chesterton, G.A.: Data Structures and Software Development in an Object-Oriented Domain: Eiffel Edition. Prentice Hall, Englewood Cliffs (2001)
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 2008 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Findler, R.B., Guo, Sy., Rogers, A. (2008). Lazy Contract Checking for Immutable Data Structures. In: Chitil, O., Horváth, Z., Zsók, V. (eds) Implementation and Application of Functional Languages. IFL 2007. Lecture Notes in Computer Science, vol 5083. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-85373-2_7
Download citation
DOI: https://doi.org/10.1007/978-3-540-85373-2_7
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-85372-5
Online ISBN: 978-3-540-85373-2
eBook Packages: Computer ScienceComputer Science (R0)