views:

146

answers:

1

I am testing a function called extractions that operates over any list.

extractions :: [a] -> [(a,[a])]
extractions [] = []
extractions l = extract l []
    where extract [] _ = []
          extract (x:xs) prev = (x, prev++xs) : extract xs (x : prev)

I want to test it, for example, with

import Test.QuickCheck.Batch    
prop_len l = length l == length (extractions l)
main = runTests "extractions" defOpt [run prop_len]

But this won't compile; I have to supply a type either for run or prop_len, because QuickCheck can't generate [a], it has to generate something concrete. So I chose Int:

main = runTests "extractions" defOpt [r prop_len]
    where r = run :: ([Int] -> Bool) -> TestOptions -> IO TestResult

Is there any way to get QuickCheck to choose a for me instead of having it specified in the type of run?

+3  A: 

The quickcheck manual says "no":

Properties must have monomorphic types. `Polymorphic' properties, such as the one above, must be restricted to a particular type to be used for testing. It is convenient to do so by stating the types of one or more arguments in a

where types = (x1 :: t1, x2 :: t2, ...)

clause...

ordnungswidrig