Polymorphic Contracts

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.

[1]  Amal Ahmed,et al.  Parametric Polymorphism through Run-Time Sealing or, Theorems for Low, Low Prices! , 2008, ESOP.

[2]  Cormac Flanagan,et al.  Unifying Hybrid Types and Contracts , 2007, Trends in Functional Programming.

[3]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[4]  Matthias Felleisen,et al.  Contracts for higher-order functions , 2002, ICFP '02.

[5]  Benjamin C. Pierce,et al.  Contracts made manifest , 2010, POPL '10.

[6]  David Walker,et al.  Dynamic Typing with Dependent Types , 2004, IFIP TCS.

[7]  Philip Wadler,et al.  Blame for all , 2011, POPL '11.

[8]  Walid Taha,et al.  Gradual Typing for Objects , 2007, ECOOP.

[9]  Matthias Felleisen,et al.  A Syntactic Approach to Type Soundness , 1994, Inf. Comput..

[10]  Philip Wadler,et al.  Well-Typed Programs Can't Be Blamed , 2009, ESOP.

[11]  Benjamin C. Pierce,et al.  Advanced Topics In Types And Programming Languages , 2004 .

[12]  Robert Bruce Findler,et al.  Relationally-parametric polymorphic contracts , 2007, DLS '07.

[13]  Jeremy G. Siek Gradual Typing for Functional Languages , 2006 .

[14]  Cormac Flanagan,et al.  Hybrid type checking , 2006, POPL '06.

[15]  Benjamin C. Pierce,et al.  Relating Cryptography and Polymorphism , 2000 .

[16]  David Aspinall,et al.  Subtyping dependent types , 1996, Proceedings 11th Annual IEEE Symposium on Logic in Computer Science.

[17]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[18]  Sam Tobin-Hochstadt,et al.  Practical Variable-Arity Polymorphism , 2009, ESOP.