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
- Matthias Blume and David A. McAllester. Sound and complete models of contracts. Journal of Functional Programming, 16(4-5):375--414, 2006. Google Scholar
Digital Library
- Olaf Chitil and Frank Huch. Monadic, prompt lazy assertions in haskell. In APLAS, pages 38--53, 2007. Google Scholar
Digital Library
- Robert Bruce Findler. Contracts as pairs of projections. In Symposium on Logic Programming, pages 226--241, 2006. Google Scholar
Digital Library
- Robert Bruce Findler and Matthias Felleisen. Contracts for higher-order functions. In International Conference on Functional Programming (ICFP), pages 48--59, 2002. Google Scholar
Digital Library
- Cormac Flanagan. Hybrid type checking. In POPL, pages 245--256, 2006. Google Scholar
Digital Library
- Jessica Gronski and Cormac Flanagan. Unifying hybrid types and contracts. In Trends in Functional Programming (TFP), 2007.Google Scholar
- 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 Scholar
- Arjun Guha, Jacob Matthews, Robert Bruce Findler, and Shriram Krishnamurthi. Relationally-parametric polymorphic contracts. In DLS, pages 29--40, 2007. Google Scholar
Digital Library
- Ralf Hinze, Johan Jeuring, and Andres L¨oh. Typed contracts for functional programming. In Functional and Logic Programming (FLOPS), pages 208--225, 2006. Google Scholar
Digital Library
- Kenneth Knowles and Cormac Flanagan. Hybrid type checking. To appear in TOPLAS., 2009. Google Scholar
Digital Library
- Bertrand Meyer. Eiffel: the language. Prentice-Hall, Inc., 1992. ISBN 0-13-247925-7. Google Scholar
Digital Library
- Xinming Ou, Gang Tan, Yitzhak Mandelbaum, and DavidWalker. Dynamic typing with dependent types. In IFIP TCS, pages 437--450, 2004.Google Scholar
Cross Ref
- Sam Tobin-Hochstadt and Matthias Felleisen. The design and implementation of typed scheme. In Principles of Programming Languages (POPL), pages 395--406, 2008. Google Scholar
Digital Library
- Philip Wadler and Robert Bruce Findler. Well-typed programs can't be blamed. In Workshop on Scheme and Functional Programming, 2007.Google Scholar
- Philip Wadler and Robert Bruce Findler. Well-typed programs can't be blamed. In European Symposium on Programming (ESOP), pages 1--16, 2009. Google Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Contracts made manifest






Comments