I want to do some similar tests for different types in my library.
To simplify the situation, suppose I have several types of vectors that implement the Num class, and I want to generate the same check for the QuickCheck property prop_absNorm xy = abs x + abs y >= abs (x+y) , which will work on all types in library.
I generate such properties using TH:
$(writeTests (\t -> [d| prop_absNorm :: $(t) -> $(t) -> Bool prop_absNorm xy = abs x + abs y >= abs (x+y) |]) )
My test generation function has the following signature:
writeTests :: (TypeQ -> Q [Dec]) -> Q [Dec]
This function searches for all instances of my VectorMath (n::Nat) t vector class (and, at the same time, Num instances) through reify ''VectorMath and accordingly generates all the support functions. -ddump-splices shows something like this:
prop_absNormIntX4 :: Vector 4 Int -> Vector 4 Int -> Bool prop_absNormIntX4 xy = abs x + abs y >= abs (x+y) prop_absNormCIntX4 :: Vector 4 CInt -> Vector 4 CInt -> Bool prop_absNormCIntX4 xy = abs x + abs y >= abs (x+y) ... prop_absNormFloatX4 :: Vector 4 Float -> Vector 4 Float -> Bool prop_absNormFloatX4 xy = abs x + abs y >= abs (x+y) prop_absNormFloatX3 :: Vector 3 Float -> Vector 3 Float -> Bool prop_absNormFloatX3 xy = abs x + abs y >= abs (x+y)
The problem is that all properties written by hand are checked, but not generated.
Note 1: I created and did not generate properties in one file (i.e. the expression TH $(..) is in the same file as the other details).
Note 2: the list of types for creating prop functions is a variable - I want to add other instances of VectorMath later, so they are automatically added to the test list.
I believe the problem is that the HTF (which supposedly uses TH too) is parsing the source file, not the one with the generated code, but I cannot understand why this is happening.
So my question is: how to solve this problem? If it is impossible to use TH-generated details, is it possible to run QuickCheck tests on different types (i.e. Replaces them with prop_absNorm :: Vector 4 a -> Vector 4 a -> Bool )?
Another alternative would be to use TH further to add test entries manually in htf_Main, but I have not figured out how to do this yet; and it doesn't seem like a good clean solution.