Since Findler and Felleisen (Findler, R. B. & Felleisen, M. 2002) introduced higher-order contracts, many variants have been proposed. Broadly, these fall into two groups: some follow Findler and Felleisen (2002) 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 (Gronski, J. & Flanagan, C. 2007), who defined a latent calculus λC and a manifest calculus λH, gave a translation I from λC to λH, and proved that if a λC term reduces to a constant, so does its I-image. We enrich their account with a translation I 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 I and I 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.
[1]
David A. McAllester,et al.
Sound and complete models of contracts
,
2006,
Journal of Functional Programming.
[2]
Matthias Felleisen,et al.
Contracts for higher-order functions
,
2002,
ICFP '02.
[3]
Ralf Hinze,et al.
Typed Contracts for Functional Programming
,
2006,
FLOPS.
[4]
Matthias Felleisen,et al.
A Syntactic Approach to Type Soundness
,
1994,
Inf. Comput..
[5]
Luca Cardelli,et al.
An Extension of System F with Subtyping
,
1994,
Inf. Comput..
[6]
Robert Bruce Findler,et al.
Relationally-parametric polymorphic contracts
,
2007,
DLS '07.
[7]
James Cheney.
Scrap your nameplate: (functional pearl)
,
2005,
ICFP '05.
[8]
Robert Bruce Findler,et al.
Contracts as Pairs of Projections
,
2006,
FLOPS.
[9]
John Clements.
Proceedings of the Scheme and Functional Programming Workshop
,
2009
.
[10]
Stephanie Weirich,et al.
LNgen: Tool Support for Locally Nameless Representations
,
2010
.
[11]
Kenneth Knowles,et al.
Hybrid type checking
,
2010,
TOPL.
[12]
Bertrand Meyer,et al.
Eiffel: The Language
,
1991
.
[13]
Simon L. Peyton Jones,et al.
Imperative functional programming
,
1993,
POPL '93.
[14]
Olaf Chitil,et al.
Monadic, Prompt Lazy Assertions in Haskell
,
2007,
APLAS.