skip to main content
research-article

Testing type class laws

Authors Info & Claims
Published:13 September 2012Publication History
Skip Abstract Section

Abstract

The specification of a class in Haskell often starts with stating, in comments, the laws that should be satisfied by methods defined in instances of the class, followed by the type of the methods of the class. This paper develops a framework that supports testing such class laws using QuickCheck. Our framework is a light-weight class law testing framework, which requires a limited amount of work per class law, and per datatype for which the class law is tested. We also show how to test class laws with partially-defined values. Using partially-defined values, we show that the standard lazy and strict implementations of the state monad do not satisfy the expected laws.

References

  1. J.-P. Bernardy, P. Jansson, and K. Claessen. Testing polymorphic properties. In ESOP'10, volume 6012 of Lecture Notes in Computer Science, pages 125--144. Springer, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. M. M. T. Chakravarty, G. Keller, S. Peyton Jones, and S. Marlow. Associated types with class. In POPL'05, pages 1--13. ACM, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. K. Claessen and J. Hughes. QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs. In ICFP'00, pages 286--279. ACM, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. N. A. Danielsson and P. Jansson. Chasing bottoms: A case study in program verification in the presence of partial and infinite values. In MPC'04, volume 3125 of Lecture Notes in Computer Science, pages 85--109. Springer, 2004.Google ScholarGoogle Scholar
  5. N. A. Danielsson, J. Hughes, P. Jansson, and J. Gibbons. Fast and loose reasoning is morally correct. In POPL'06, pages 206--217. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. C. Elliott. Checkers. A Haskell package available on Hackage, 2012. URL http://hackage.haskell.org/package/checkers-0.2.9.Google ScholarGoogle Scholar
  7. J. Gibbons and R. Hinze. Just do it: simple monadic equational reasoning. In ICFP'11, pages 2--14. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. P. Jansson and J. Jeuring. Polytypic data conversion programs. Science of Computer Programming, 43 (1): 35--75, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. S. Marlow, editor. Haskell 2010 Language Report, 2010. http://www.haskell.org/onlinereport/haskell2010/.Google ScholarGoogle Scholar
  10. C. Runciman, M. Naylor, and F. Lindblad. Smallcheck and lazy smallcheck: automatic exhaustive testing for small values. In Haskell'08, pages 37--48. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. W. Taysom. Quickchecking type class laws. Blog post, 2011. URL http://www.cubiclemuses.com/cm/articles/2011/07/14/quickchecking-type-class-laws/.Google ScholarGoogle Scholar

Index Terms

  1. Testing type class laws

    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 47, Issue 12
      Haskell '12
      December 2012
      157 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2430532
      Issue’s Table of Contents
      • cover image ACM Conferences
        Haskell '12: Proceedings of the 2012 Haskell Symposium
        September 2012
        168 pages
        ISBN:9781450315746
        DOI:10.1145/2364506

      Copyright © 2012 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 13 September 2012

      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!