TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Using Haskell's QuickCheck for Python

43 pointsby Russell91about 10 years ago

5 comments

toolsliveabout 10 years ago
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.
评论 #9242640 未加载
rusbusabout 10 years ago
Or of course, you can skip haskell and just use the python port <a href="https://pypi.python.org/pypi/pytest-quickcheck" rel="nofollow">https:&#x2F;&#x2F;pypi.python.org&#x2F;pypi&#x2F;pytest-quickcheck</a>
评论 #9242007 未加载
cpaabout 10 years ago
Neat, but there&#x27;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 -&gt; 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.<p>Also, you have to make sure haskell&#x27;s Ints and Python&#x27;s Int are the same on your platform (one could be 32 bits and the other 64 bits).<p>[0] we did not prove anything, but just ran a bunch of tests, but you get the point.
评论 #9242399 未加载
bensummersabout 10 years ago
You might also want to have a look at hypothesis:<p><a href="https://github.com/DRMacIver/hypothesis" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;DRMacIver&#x2F;hypothesis</a><p><a href="http://hypothesis.readthedocs.org/en/master/" rel="nofollow">http:&#x2F;&#x2F;hypothesis.readthedocs.org&#x2F;en&#x2F;master&#x2F;</a><p>It&#x27;s a QuickCheck inspired python testing library with some interesting new ideas.
codelionabout 10 years ago
Neat trick using the FFI for this. Also, quickCheck like libraries are available in other languages e.g JUnit-QuickCheck for Java - <a href="https://blog.sourceclear.com/property-based-testing-for-java/" rel="nofollow">https:&#x2F;&#x2F;blog.sourceclear.com&#x2F;property-based-testing-for-java...</a>