[Haskell-cafe] QuickChecking classes

Derek Elkins ddarius at hotpop.com
Wed Mar 23 15:34:13 EST 2005

On Wed, 23 Mar 2005 13:08:43 -0500
Benjamin Pierce <bcpierce at cis.upenn.edu> wrote:

> 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.

More information about the Haskell-Cafe mailing list