Abstract
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.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Meyer, B.: Applying ‘design by contract’. IEEE Computer 25(10), 40–51 (1992)
Meyer, B.: Eiffel: The Language. Prentice Hall, Englewood Cliffs (1992)
Findler, R.B., Felleisen, M.: Contracts for higher-order functions. ACM SIGPLAN Notices 37(9), 48–59 (2002)
Peyton Jones, S.: Haskell 98 Language and Libraries. Cambridge University Press, Cambridge (2003)
The GHC Team: The Glorious Glasgow Haskell Compilation System User’s Guide, Version 6.4.1 (2005), http://www.haskell.org/ghc/
Blume, M., McAllester, D.: A sound (and complete) model of contracts. ACM SIGPLAN Notices 39(9), 189–200 (2004)
Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: POPL 2003, pp. 224–235. ACM Press, New York (2003)
Hinze, R.: Fun with phantom types. In: Gibbons, J., de Moor, O. (eds.) The Fun of Programming, pp. 245–262. Palgrave Macmillan, Basingstoke (2003); ISBN 1-4039-0772-2 hardback, ISBN 0-333-99285-7 paperback
Peyton Jones, S., Washburn, G., Weirich, S.: Wobbly types: Type inference for generalised algebraic data types. Technical Report MS-CIS-05-26, University of Pennsylvania (2005)
Hinze, R.: Polytypic values possess polykinded types. Science of Computer Programming 43, 129–159 (2002)
Hutton, G.: A tutorial on the universality and expressiveness of fold. Journal of Functional Programming 9(4), 355–372 (1999)
Wadler, P.: Theorems for free! In: The Fourth International Conference on Functional Programming Languages and Computer Architecture (FPCA 1989), London, UK, pp. 347–359. Addison-Wesley Publishing Company, Reading (1989)
Findler, R.B.: Behavioral software contracts (dissertation). Technical Report TR02-402, Department of Computer Science, Rice University (2002)
Blume, M., McAllester, D.: Sound and complete models of contracts. Journal of Functional Programming (2006) (to appear)
Findler, R.B., Blume, M., Felleisen, M.: An investigation of contracts as projections. Technical Report TR-2004-02, The University of Chicago (2004)
Nordström, B., Petersson, K., Smith, J.: Programming in Martin-Löf’s Type Theory. Oxford University Press, Oxford (1990)
Claessen, K., Runciman, C., Chitil, O., Hughes, J., Wallace, M.: Testing and tracing lazy functional programs using Quickcheck and Hat. In: Jeuring, J., Peyton Jones, S. (eds.) AFP 2002. LNCS, vol. 2638. Springer, Heidelberg (2003)
Chitil, O., McNeill, D., Runciman, C.: Lazy assertions. In: Trinder, P., Michaelson, G.J., Peña, R. (eds.) IFL 2003. LNCS, vol. 3145, pp. 1–19. Springer, Heidelberg (2004)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2006 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Hinze, R., Jeuring, J., Löh, A. (2006). Typed Contracts for Functional Programming. In: Hagiya, M., Wadler, P. (eds) Functional and Logic Programming. FLOPS 2006. Lecture Notes in Computer Science, vol 3945. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11737414_15
Download citation
DOI: https://doi.org/10.1007/11737414_15
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-33438-5
Online ISBN: 978-3-540-33439-2
eBook Packages: Computer ScienceComputer Science (R0)