research-article

Contracts made manifest

Published:17 January 2010Publication History

Abstract

Since Findler and Felleisen introduced higher-order contracts , many variants have been proposed. Broadly, these fall into two groups: some follow Findler and Felleisen in using latent contracts, purely dynamic checks that are transparent to the type system; others use manifest contracts, where refinement types record the most recent check that has been applied to each value. These two approaches are commonly assumed to be equivalent---different ways of implementing the same idea, one retaining a simple type system, and the other providing more static information. Our goal is to formalize and clarify this folklore understanding.

Our work extends that of Gronski and Flanagan, who defined a latent calculus λ C and a manifest calculus λ H , gave a translation φ from λ C to λ H , and proved that, if a λ C term reduces to a constant, then so does its φ-image. We enrich their account with a translation Ψ from λ H to λ C and prove an analogous theorem.

We then generalize the whole framework to dependent contracts , whose predicates can mention free variables. This extension is both pragmatically crucial, supporting a much more interesting range of contracts, and theoretically challenging. We define dependent versions of λ H and two dialects ("lax" and "picky") of λ C , establish type soundness---a substantial result in itself, for λ H ---and extend φ and Ψ accordingly. Surprisingly, the intuition that the latent and manifest systems are equivalent now breaks down: the extended translations preserve behavior in one direction but, in the other, sometimes yield terms that blame more.

References

  1. Matthias Blume and David A. McAllester. Sound and complete models of contracts. Journal of Functional Programming, 16(4-5):375--414, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Olaf Chitil and Frank Huch. Monadic, prompt lazy assertions in haskell. In APLAS, pages 38--53, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Robert Bruce Findler. Contracts as pairs of projections. In Symposium on Logic Programming, pages 226--241, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Robert Bruce Findler and Matthias Felleisen. Contracts for higher-order functions. In International Conference on Functional Programming (ICFP), pages 48--59, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Cormac Flanagan. Hybrid type checking. In POPL, pages 245--256, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Jessica Gronski and Cormac Flanagan. Unifying hybrid types and contracts. In Trends in Functional Programming (TFP), 2007.Google ScholarGoogle Scholar
  7. Jessica Gronski, Kenneth Knowles, Aaron Tomb, Stephen N. Freund, and Cormac Flanagan. Sage: Hybrid checking for flexible specifications. In Scheme and Functional Programming Workshop, pages 93--104, 2006.Google ScholarGoogle Scholar
  8. Arjun Guha, Jacob Matthews, Robert Bruce Findler, and Shriram Krishnamurthi. Relationally-parametric polymorphic contracts. In DLS, pages 29--40, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Ralf Hinze, Johan Jeuring, and Andres L¨oh. Typed contracts for functional programming. In Functional and Logic Programming (FLOPS), pages 208--225, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Kenneth Knowles and Cormac Flanagan. Hybrid type checking. To appear in TOPLAS., 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Bertrand Meyer. Eiffel: the language. Prentice-Hall, Inc., 1992. ISBN 0-13-247925-7. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Xinming Ou, Gang Tan, Yitzhak Mandelbaum, and DavidWalker. Dynamic typing with dependent types. In IFIP TCS, pages 437--450, 2004.Google ScholarGoogle ScholarCross RefCross Ref
  13. Sam Tobin-Hochstadt and Matthias Felleisen. The design and implementation of typed scheme. In Principles of Programming Languages (POPL), pages 395--406, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Philip Wadler and Robert Bruce Findler. Well-typed programs can't be blamed. In Workshop on Scheme and Functional Programming, 2007.Google ScholarGoogle Scholar
  15. Philip Wadler and Robert Bruce Findler. Well-typed programs can't be blamed. In European Symposium on Programming (ESOP), pages 1--16, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Dana N. Xu, Simon Peyton Jones, and Koen Claessen. Static contract checking for haskell. In Principles of Programming Languages (POPL), pages 41--52, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Contracts made manifest

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in

            Full Access

            • Published in

              cover image ACM SIGPLAN Notices
              ACM SIGPLAN Notices  Volume 45, Issue 1
              POPL '10
              January 2010
              500 pages
              ISSN:0362-1340
              EISSN:1558-1160
              DOI:10.1145/1707801
              Issue’s Table of Contents
              • cover image ACM Conferences
                POPL '10: Proceedings of the 37th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
                January 2010
                520 pages
                ISBN:9781605584799
                DOI:10.1145/1706299

              Copyright © 2010 ACM

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 17 January 2010

              Check for updates

              Qualifiers

              • research-article

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader
            About Cookies On This Site

            We use cookies to ensure that we give you the best experience on our website.

            Learn more

            Got it!