[Haskell-cafe] reimplementing break (incorrectly) "quickcheck p list" gives me feedback that it breaks on list, but not what predicate test caused the breakage

Josef Svenningsson josef.svenningsson at gmail.com
Fri Jul 6 11:17:04 EDT 2007


On 7/6/07, Thomas Hartman <thomas.hartman at db.com> wrote:
>
> I am a total quickcheck noob. Is there a way to find out what predicate test
> "<function>" is, below?
>
The trick that I know of to do that is to not generate a function in
the first place, but a data type which can represent various functions
of this type. Whenever we want to use the data type as a function in
the test we convert it to a function. Let's take an example:

data IntFun = Plus5  | Mult5 deriving show

apply :: IntFun -> Int -> Int
apply Plus = (+ 5)
apply Mult = (* 5)

instance Arbitrary IntFun where
  arbitrary = elements [Plus,Mult]

prop_foo f a = apply f a == a

Ofcourse the data type will typically be much more complicated
depending on what kind of functions you want to be able to generate.

This trick is documented in the following paper:
http://www.st.cs.ru.nl/papers/2006/koop2006-TestingOfHigherOrderFunctionsAPLAS.pdf

HTH,

Josef


More information about the Haskell-Cafe mailing list