On 7/6/07, Thomas Hartman <[EMAIL PROTECTED]> 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
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to