Abstract
We study algebraic data types in a manifest contract system, a software contract system where contract information occurs as refinement types. We first compare two simple approaches: refinements on type constructors and refinements on data constructors. For example, lists of positive integers can be described by {l:int list | for_all (lambda y. y > 0) l} in the former, whereas by a user-defined datatype pos_list with cons of type {x:int | x > 0} X pos_list -> pos_list in the latter. The two approaches are complementary: the former makes it easier for a programmer to write types and the latter enables more efficient contract checking. To take the best of both worlds, we propose (1) a syntactic translation from refinements on type constructors to equivalent refinements on data constructors and (2) dynamically checked casts between different but compatible datatypes such as int list and pos_list. We define a manifest contract calculus to formalize the semantics of the casts and prove that the translation is correct.
Supplemental Material
Available for Download
- The Agda 2 homepage. http://wiki.portal.chalmers.se/ agda/pmwiki.php.Google Scholar
- The Coq proof assistant. http://coq.inria.fr/.Google Scholar
- R. Atkey, P. Johann, and N. Ghani. Refining inductive types. Logical Methods in Computer Science, 8(2:9):1--30, 2012.Google Scholar
- J. F. Belo, M. Greenberg, A. Igarashi, and B. C. Pierce. Polymorphic contracts. In Proc. of ESOP, volume 6602 of LNCS, pages 18--37, 2011. Google Scholar
Digital Library
- G. M. Bierman, A. D. Gordon, C. Hriţcu, and D. Langworthy. Se- mantic subtyping with an SMT solver. In Proc. of ACM ICFP, pages 105--116, 2010. Google Scholar
Digital Library
- M. Blume and D. A. McAllester. Sound and complete models of contracts. J. Funct. Program., 16(4-5):375--414, July 2006. Google Scholar
Digital Library
- O. Chitil. A semantics for lazy assertions. In Proc. of ACM PEPM, pages 141--150, 2011. Google Scholar
Digital Library
- M. Felleisen and R. Hieb. The revised report on the syntactic theories of sequential control and state. Theor. Comput. Sci., 103(2):235--271, Sept. 1992. Google Scholar
Digital Library
- R. B. Findler and M. Felleisen. Contracts for higher-order functions. In Proc. of ACM ICFP, pages 48--59, 2002. Google Scholar
Digital Library
- R. B. Findler, S. Guo, and A. Rogers. Lazy contract checking for immutable data structures. In Proc. of IFL, volume 5083 of LNCS, pages 111--128, 2008. Google Scholar
Digital Library
- C. Flanagan. Hybrid type checking. In Proc. of ACM POPL, pages 245--256, 2006. Google Scholar
Digital Library
- T. Freeman and F. Pfenning. Refinement types for ML. In Proc. of ACM PLDI, pages 268--277, 1991. Google Scholar
Digital Library
- M. Greenberg. Manifest Contracts. PhD thesis, University of Pennsylvania, 2013. Google Scholar
Digital Library
- M. Greenberg, B. C. Pierce, and S. Weirich. Contracts made manifest. In Proc. of ACM POPL, pages 353--364, 2010. Google Scholar
Digital Library
- J. Gronski, K. Knowles, A. Tomb, S. N. Freund, and C. Flanagan. Sage: Hybrid checking for flexible specifications. In Scheme and Functional Programming Workshop, pages 93--104, 2006.Google Scholar
- D. Herman, A. Tomb, and C. Flanagan. Space-efficient gradual typing. In Trends in Functional Prog. (TFP), 2007.Google Scholar
- M. Kawaguchi, P. M. Rondon, and R. Jhala. Type-based data structure verification. In Proc. of ACM PLDI, pages 304--315, 2009. Google Scholar
Digital Library
- K. Knowles and C. Flanagan. Hybrid type checking. ACM TOPLAS, 32(2:6):1--34, Feb. 2010. Google Scholar
Digital Library
- K. Knowles, A. Tomb, J. Gronski, S. N. Freund, and C. Flanagan. Sage: Unified hybrid checking for first-class types, general refinement types, and dynamic (extended report). Technical report, UCSC, 2007.Google Scholar
- C. McBride. Ornamental algebras, algebraic ornaments. J. Funct. Program., 2014. To appear.Google Scholar
- B. Meyer. Object-Oriented Software Construction, 1st Edition. Prentice-Hall, 1988. ISBN 0--13--629031-0. Google Scholar
Digital Library
- P. C. Nguyen, S. Tobin-Hochstadt, and D. Van Horn. Soft contract verification. In ACM ICFP, 2014. Google Scholar
Digital Library
- B. C. Pierce. Types and Programming Languages. The MIT Press, Cambridge, MA, USA, 2002. ISBN 0--262--16209--1. Google Scholar
Digital Library
- P. M. Rondon, M. Kawaguchi, , and R. Jhala. Liquid types. In ACM PLDI, 2008. Google Scholar
Digital Library
- J. G. Siek and P. Wadler. Threesomes, with and without blame. In Proc. of ACM POPL, pages 365--376, 2010. Google Scholar
Digital Library
- D. A. Turner. Miranda: A non-strict functional language with poly- morphic types. In Proc. of ACM FPCA, volume 201 of LNCS, pages 1--16, 1985. Google Scholar
Digital Library
- N. Vazou, P. M. Rondon, and R. Jhala. Abstract refinement types. In Proc. of ESOP, volume 7792 of LNCS, pages 209--228, 2013. Google Scholar
Digital Library
- N. Vazou, E. L. Seidel, R. Jhala, D. Vytiniotis, and S. Peyton Jones. Refinement types for Haskell. In ACM ICFP, 2014. Google Scholar
Digital Library
- A. K. Wright and M. Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1):38--94, 1994. Google Scholar
Digital Library
- H. Xi. Dependent ML: An approach to practical programming with dependent types. J. Funct. Program., 17(2):215--286, Mar. 2007. Google Scholar
Digital Library
- H. Xi and F. Pfenning. Dependent types in practical programming. In Proc. of ACM POPL, pages 214--227, 1999. Google Scholar
Digital Library
- D. N. Xu. Hybrid contract checking via symbolic simplification. In Proc. of ACM PEPM, pages 107--116, 2012. Google Scholar
Digital Library
- D. N. Xu, S. L. Peyton Jones, and K. Claessen. Static contract checking for Haskell. In Proc. of ACM POPL, pages 41--52, 2009. Google Scholar
Digital Library
Index Terms
Manifest Contracts for Datatypes







Comments