[Haskell-beginners] Quickcheck2 - writing a modifier for test data

Nathan Hüsken nathan.huesken at posteo.de
Sun Mar 31 12:21:48 CEST 2013


Hey,

Using quickcheck2 I want to generate test data, that is a tuple of 
integers where both elements are >=0 and < 8.

So I am trying to write a modifier (in the sense of the modifiers found 
in Modifiers.hs):

newtype ValidPos   = ValidPos Pos        deriving Show

instance Arbitrary ValidPos where
   arbitrary = do
     x <- elements [0..7]
     y <- elements [0..7]
     return (ValidPos (x,y))

prop_dummy (ValidPos pos) = fst pos > 0

tests = [ testGroup "Tests" [
             testProperty "dummy" prop_dummy
           ]
         ]

main = defaultMain tests

doing so gives me this error:

     No instance for (QuickCheck-2.4.2:Test.QuickCheck.Arbitrary.Arbitrary
                        ValidPos)
       arising from a use of `testProperty'
     Possible fix:
       add an instance declaration for
       (QuickCheck-2.4.2:Test.QuickCheck.Arbitrary.Arbitrary ValidPos)
     In the expression: testProperty "dummy" prop_dummy
     In the second argument of `testGroup', namely
       `[testProperty "dummy" prop_dummy]'
     In the expression:
       testGroup "Tests" [testProperty "dummy" prop_dummy]

I declared the instance, why canit not be found?

Thanks!
Nathan



More information about the Beginners mailing list