skip to main content
research-article

Manifest Contracts for Datatypes

Published:14 January 2015Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

References

  1. The Agda 2 homepage. http://wiki.portal.chalmers.se/ agda/pmwiki.php.Google ScholarGoogle Scholar
  2. The Coq proof assistant. http://coq.inria.fr/.Google ScholarGoogle Scholar
  3. R. Atkey, P. Johann, and N. Ghani. Refining inductive types. Logical Methods in Computer Science, 8(2:9):1--30, 2012.Google ScholarGoogle Scholar
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. M. Blume and D. A. McAllester. Sound and complete models of contracts. J. Funct. Program., 16(4-5):375--414, July 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. O. Chitil. A semantics for lazy assertions. In Proc. of ACM PEPM, pages 141--150, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. R. B. Findler and M. Felleisen. Contracts for higher-order functions. In Proc. of ACM ICFP, pages 48--59, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. C. Flanagan. Hybrid type checking. In Proc. of ACM POPL, pages 245--256, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. T. Freeman and F. Pfenning. Refinement types for ML. In Proc. of ACM PLDI, pages 268--277, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. M. Greenberg. Manifest Contracts. PhD thesis, University of Pennsylvania, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. M. Greenberg, B. C. Pierce, and S. Weirich. Contracts made manifest. In Proc. of ACM POPL, pages 353--364, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle Scholar
  16. D. Herman, A. Tomb, and C. Flanagan. Space-efficient gradual typing. In Trends in Functional Prog. (TFP), 2007.Google ScholarGoogle Scholar
  17. M. Kawaguchi, P. M. Rondon, and R. Jhala. Type-based data structure verification. In Proc. of ACM PLDI, pages 304--315, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. K. Knowles and C. Flanagan. Hybrid type checking. ACM TOPLAS, 32(2:6):1--34, Feb. 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle Scholar
  20. C. McBride. Ornamental algebras, algebraic ornaments. J. Funct. Program., 2014. To appear.Google ScholarGoogle Scholar
  21. B. Meyer. Object-Oriented Software Construction, 1st Edition. Prentice-Hall, 1988. ISBN 0--13--629031-0. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. P. C. Nguyen, S. Tobin-Hochstadt, and D. Van Horn. Soft contract verification. In ACM ICFP, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. B. C. Pierce. Types and Programming Languages. The MIT Press, Cambridge, MA, USA, 2002. ISBN 0--262--16209--1. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. P. M. Rondon, M. Kawaguchi, , and R. Jhala. Liquid types. In ACM PLDI, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. J. G. Siek and P. Wadler. Threesomes, with and without blame. In Proc. of ACM POPL, pages 365--376, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. N. Vazou, P. M. Rondon, and R. Jhala. Abstract refinement types. In Proc. of ESOP, volume 7792 of LNCS, pages 209--228, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. N. Vazou, E. L. Seidel, R. Jhala, D. Vytiniotis, and S. Peyton Jones. Refinement types for Haskell. In ACM ICFP, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. A. K. Wright and M. Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1):38--94, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. H. Xi. Dependent ML: An approach to practical programming with dependent types. J. Funct. Program., 17(2):215--286, Mar. 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. H. Xi and F. Pfenning. Dependent types in practical programming. In Proc. of ACM POPL, pages 214--227, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. D. N. Xu. Hybrid contract checking via symbolic simplification. In Proc. of ACM PEPM, pages 107--116, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Manifest Contracts for Datatypes

              Recommendations

              Comments

              Login options

              Check if you have access through your login credentials or your institution to get full access on this article.

              Sign in

              Full Access

              • Published in

                cover image ACM SIGPLAN Notices
                ACM SIGPLAN Notices  Volume 50, Issue 1
                POPL '15
                January 2015
                682 pages
                ISSN:0362-1340
                EISSN:1558-1160
                DOI:10.1145/2775051
                • Editor:
                • Andy Gill
                Issue’s Table of Contents
                • cover image ACM Conferences
                  POPL '15: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages
                  January 2015
                  716 pages
                  ISBN:9781450333009
                  DOI:10.1145/2676726

                Copyright © 2015 ACM

                Publisher

                Association for Computing Machinery

                New York, NY, United States

                Publication History

                • Published: 14 January 2015

                Check for updates

                Qualifiers

                • research-article

              PDF Format

              View or Download as a PDF file.

              PDF

              eReader

              View online with eReader.

              eReader
              About Cookies On This Site

              We use cookies to ensure that we give you the best experience on our website.

              Learn more

              Got it!