Typed Contracts for Functional Programming

A robust software component fulfills a contract: it expects data satisfying a certain property and promises to return data satisfying another property. The object-oriented community uses the design-by-contract approach extensively. Proposals for language extensions that add contracts to higher-order functional programming have appeared recently. In this paper we propose an embedded domain-specific language for typed, higher-order and first-class contracts, which is both more expressive than previous proposals, and allows for a more informative blame assignment. We take some first steps towards an algebra of contracts, and we show how to define a generic contract combinator for arbitrary algebraic data types. The contract language is implemented as a library in Haskell using the concept of generalised algebraic data types.

[1]  David A. McAllester,et al.  A sound (and complete) model of contracts , 2004, ICFP '04.

[2]  David A. McAllester,et al.  Sound and complete models of contracts , 2006, Journal of Functional Programming.

[3]  Graham Hutton,et al.  A tutorial on the universality and expressiveness of fold , 1999, Journal of Functional Programming.

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

[5]  Bengt Nordström,et al.  Programming in Martin-Lo¨f's type theory: an introduction , 1990 .

[6]  Koen Claessen,et al.  Testing and Tracing Lazy Functional Programs Using QuickCheck and Hat , 2002, Advanced Functional Programming.

[7]  Bertrand Meyer,et al.  Eiffel: The Language , 1991 .

[8]  Bertrand Meyer,et al.  Applying 'design by contract' , 1992, Computer.

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

[10]  Matthias Felleisen,et al.  Behavioral contracts and behavioral subtyping , 2001, ESEC/FSE-9.

[11]  Werner Kluge,et al.  Implementation of Functional Languages , 1996, Lecture Notes in Computer Science.

[12]  Ralf Hinze Polytypic Values Possess Polykinded Types , 2000, MPC.

[13]  Gang Chen,et al.  Guarded recursive datatype constructors , 2003, POPL '03.

[14]  Ralf Hinze,et al.  Fun with phantom types , 2003 .

[15]  Simon Peyton Jones,et al.  Wobbly types: type inference for generalised algebraic data types∗ , 2004 .

[16]  Bengt Nordström,et al.  Programming in Martin-Löf's Type Theory , 1990 .

[17]  Philip Wadler XQuery: A Typed Functional Language for Querying XML , 2002, Advanced Functional Programming.

[18]  Colin Runciman,et al.  Lazy Assertions , 2003, IFL.

[19]  Oege de Moor,et al.  The Fun of Programming , 2003 .

[20]  Matthias Felleisen,et al.  An Investigation of Contracts as Projections , 2004 .