
Today I've been learning about the wonders of QuickCheck. :-) One (obvious?) question that is not addressed in at least the original paper is how one might use QC to automatically verify the algebraic laws that are often associated with type classes. E.g., could we add some QC properties as members of the Functor class and somehow arrange (probably by some combination of automation and idiom) that they would be checked every time somebody creates an instance of Functor? Regards, - Benjamin

On Wed, 23 Mar 2005 13:08:43 -0500
Benjamin Pierce
Today I've been learning about the wonders of QuickCheck. :-)
One (obvious?) question that is not addressed in at least the original paper is how one might use QC to automatically verify the algebraic laws that are often associated with type classes. E.g., could we add some QC properties as members of the Functor class and somehow arrange (probably by some combination of automation and idiom) that they would be checked every time somebody creates an instance of Functor?
One thing we can do is write the property for any Functor, Monad, etc. Then when we instantiate a class we simply need to add prop_MyFunctorAssoc = functorAssoc :: ... MyFunctor A ... We may be able to further simplify this by using a dummy parameter to fix the class type avoiding the need to know and repeat the whole type, e.g. prop_MyFunctorAssoc = functorAssoc (undefined :: MyFunctor A) I imagine there's a way to finagle many properties into one so that we don't have to duplicate each, though it may not be worthwhile. Worse case scenario, if we don't mind throwing portability to the wind would be to have Template Haskell splice in the property functions. You could probably be even more inventive with that, but it (again) probably isn't worth it. Alternatively, some sed/awk hackery could probably accomplish more or less the same.

Benjamin Pierce
Today I've been learning about the wonders of QuickCheck. :-)
One (obvious?) question that is not addressed in at least the original paper is how one might use QC to automatically verify the algebraic laws
Some utility code is available in the QC.Utils module: http://www.haskell.org/ghc/docs/latest/html/libraries/QuickCheck/Test.QuickC... Also check out Poly and Batch under QuickCheck, tests with timeouts are cool! For other QuickCheck-related code, Isaac Jones wrote ReactiCheck for use with Yampa, and I wrote a 'test driven development' version of QuickCheck that saves failing Gen seeds for the beginning of the next run. I think Isaac Jones wrote some code that did more than QuickCheck.Utils for testing algebraic laws, I think he had some code that tested if (a >>= b) >>= c is the same as (a >>= b) >>= c is true for monad instances. I'd like to try out the unreleased version of QC. It has 'shrink' that cuts down the generated input list to give you the smallest failing case. (Not that I've seen it.) What I do not know how to do, is how to use QuickCheckM to test IO code. Specifically, the simple demo that would get me started is a QuickCheckM test that can call one of the simple command-line calculators like bc or dc and compare it against GHC's result. If someone can tell me how to do that, I will be very happy. For my daily paying contract work I'm using HUnit with a simple assertM I hacked up, but it's just not the same. -- Programming is the Magic Executable Fridge Poetry, | www.ScannedInAvian.com it is machines made of thought, fueled by ideas. | -- Shae Matijs Erisson
participants (3)
-
Benjamin Pierce
-
Derek Elkins
-
Shae Matijs Erisson