Tests a property, using test arguments, produces a test result, and prints the results and all test cases generated to stdout.
This is just a convenience function that combines quickCheckWithResult and verbose.

QuickCheck tries the shrinking candidates in the order they
appear in the list, so we put more aggressive shrinking steps
(such as replacing the whole tree by Nil) before smaller
ones (such as recursively shrinking the subtrees).

It is tempting to write the last line as
[Branch x' l' r' | x' <- shrink x, l' <- shrink l, r' <- shrink r]
but this is the wrong thing! It will force QuickCheck to shrink
x, l and r in tandem, and shrinking will stop once one of
the three is fully shrunk.

There is a fair bit of boilerplate in the code above.
We can avoid it with the help of some generic functions;
note that these only work on GHC 7.2 and above.
The function genericShrink tries shrinking a term to all of its
subterms and, failing that, recursively shrinks the subterms.
Using it, we can define shrink as:

A final gotcha: we cannot define shrink as simply shrink x = Nil:genericShrink x
as this shrinks Nil to Nil, and shrinking will go into an
infinite loop.

If all this leaves you bewildered, you might try shrink = genericShrink to begin with,
after deriving Generic and Typeable for your type. However, if your data type has any
special invariants, you will need to check that genericShrink can't break those invariants.

Used to generate a function of type a -> b.
The first argument is a value, the second a generator.
You should use variant to perturb the random generator;
the goal is that different values for the first argument will
lead to different calls to variant. An example will help:

Generates an integral number from a bounded domain. The number is
chosen from the entire range of the type, but small numbers are
generated more often than big numbers. Inspired by demands from
Phil Wadler.