from Hacker News

Using Haskell's QuickCheck for Python

by Russell91 on 3/21/15, 3:16 AM with 14 comments

  • by toolslive on 3/21/15, 7:23 AM

    I have seen people do the same with their C code: code it up in C, expose it using the ffi and use quickcheck to exercise it. It's not only Haskell that can be used this way. OCaml + ctypes is also an option.
  • by rusbus on 3/21/15, 5:26 AM

    Or of course, you can skip haskell and just use the python port https://pypi.python.org/pypi/pytest-quickcheck
  • by cpa on 3/21/15, 9:31 AM

    Neat, but there's a subtelty: at the end of the article, we only proved that square is error-free[0] when given an Int as input (because the haskell version of square is Int -> IO Int). But Python being loosely typed, I could call square on a float, and in this case nothing can be said of the python function.

    Also, you have to make sure haskell's Ints and Python's Int are the same on your platform (one could be 32 bits and the other 64 bits).

    [0] we did not prove anything, but just ran a bunch of tests, but you get the point.

  • by bensummers on 3/21/15, 7:38 AM

    You might also want to have a look at hypothesis:

    https://github.com/DRMacIver/hypothesis

    http://hypothesis.readthedocs.org/en/master/

    It's a QuickCheck inspired python testing library with some interesting new ideas.

  • by codelion on 3/21/15, 11:21 AM

    Neat trick using the FFI for this. Also, quickCheck like libraries are available in other languages e.g JUnit-QuickCheck for Java - https://blog.sourceclear.com/property-based-testing-for-java...