Polymorphic Contracts

  • João Filipe Belo
  • Michael Greenberg
  • Atsushi Igarashi
  • Benjamin C. Pierce
Part of the Lecture Notes in Computer Science book series (LNCS, volume 6602)

Abstract

Manifest contracts track precise properties by refining types with predicates—e.g., {x : Int |x > 0 } denotes the positive integers. Contracts and polymorphism make a natural combination: programmers can give strong contracts to abstract types, precisely stating pre- and post-conditions while hiding implementation details— for example, an abstract type of stacks might specify that the pop operation has input type {x :α Stack |not ( empty x )} . We formalize this combination by defining FH, a polymorphic calculus with manifest contracts, and establishing fundamental properties including type soundness and relational parametricity. Our development relies on a significant technical improvement over earlier presentations of contracts: instead of introducing a denotational model to break a problematic circularity between typing, subtyping, and evaluation, we develop the metatheory of contracts in a completely syntactic fashion, omitting subtyping from the core system and recovering it post facto as a derived property.

Keywords

contracts refinement types preconditions postconditions dynamic checking parametric polymorphism abstract datatypes syntactic proof logical relations subtyping 

References

  1. 1.
  2. 2.
    Ahmed, A., Findler, R.B., Matthews, J., Wadler, P.: Blame for all. In: Workshop on Script-to-Program Evolution, STOP (2009)Google Scholar
  3. 3.
    Ahmed, A., Findler, R.B., Siek, J., Wadler, P.: Blame for all. In: Principles of Programming Languages, POPL (2011)Google Scholar
  4. 4.
    Aspinall, D., Compagnoni, A.: Subtyping dependent types. Theor. Comput. Sci. 266(1-2), 273–309 (2001)MathSciNetCrossRefMATHGoogle Scholar
  5. 5.
    Findler, R.B., Felleisen, M.: Contracts for higher-order functions. In: International Conference on Functional Programming (ICFP), pp. 48–59 (2002)Google Scholar
  6. 6.
    Flanagan, C.: Hybrid type checking. In: POPL, pp. 245–256 (2006)Google Scholar
  7. 7.
    Greenberg, M., Pierce, B.C., Weirich, S.: Contracts made manifest. In: Principles of Programming Languages, POPL 2010 (2010)Google Scholar
  8. 8.
    Gronski, J., Flanagan, C.: Unifying hybrid types and contracts. In: Trends in Functional Programming, TFP (2007)Google Scholar
  9. 9.
    Guha, A., Matthews, J., Findler, R.B., Krishnamurthi, S.: Relationally-parametric polymorphic contracts. In: DLS, pp. 29–40 (2007)Google Scholar
  10. 10.
    Knowles, K., Flanagan, C.: Hybrid type checking (2010) (to appear in TOPLAS)Google Scholar
  11. 11.
    Matthews, J., Ahmed, A.: Parametric polymorphism through run-time sealing or, theorems for low, low prices! In: Gairing, M. (ed.) ESOP 2008. LNCS, vol. 4960, pp. 16–31. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  12. 12.
    Ou, X., Tan, G., Mandelbaum, Y., Walker, D.: Dynamic typing with dependent types. In: IFIP TCS, pp. 437–450 (2004)Google Scholar
  13. 13.
    Pierce, B., Sumii, E.: Relating cryptography and polymorphism (July 2000)Google Scholar
  14. 14.
    Pitts, A.M.: Typed operational reasoning. In: Pierce, B.C. (ed.) Advanced Topics in Types and Programming Languages, ch. 7, pp. 245–289. MIT Press, Cambridge (2005)Google Scholar
  15. 15.
    Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Scheme and Functional Programming Workshop (September 2006)Google Scholar
  16. 16.
    Strickland, T.S., Tobin-Hochstadt, S., Felleisen, M.: Practical variable-arity polymorphism. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 32–46. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  17. 17.
    Wadler, P.: Theorems for free! In: Proceedings of ACM Conference on Functional Programming and Computer Architecture (FPCA 1989), pp. 347–359, London, UK (September 1989)Google Scholar
  18. 18.
    Wadler, P., Findler, R.B.: Well-typed programs can’t be blamed. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 1–16. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  19. 19.
    Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Information and Computation 115, 38–94 (1992)MathSciNetCrossRefMATHGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2011

Authors and Affiliations

  • João Filipe Belo
    • 1
  • Michael Greenberg
    • 1
  • Atsushi Igarashi
    • 2
  • Benjamin C. Pierce
    • 1
  1. 1.University of PennsylvaniaUSA
  2. 2.Kyoto UniversityJapan

Personalised recommendations