[Haskell-cafe] QuickCheck's co-arbitrary
joelr1 at gmail.com
Wed Apr 4 09:59:18 EDT 2007
I understand that arbitrary defines the possible values.
How do I generally come up with co-arbitrary, though?
Would someone kindly explain the choice of co-arbitrary in the
following cases, specially the very last bit with "variant 1 .
instance Arbitrary Char where
arbitrary = elements ([' ', '\n', '\0'] ++ ['a'..'h'])
coarbitrary c = variant (fromEnum c `rem` 4)
instance Arbitrary Ordering where
arbitrary = elements [LT, EQ, GT]
coarbitrary LT = variant 0
coarbitrary EQ = variant 1
coarbitrary GT = variant 2
instance Arbitrary a => Arbitrary (Maybe a) where
arbitrary = frequency [ (1, return Nothing)
, (3, liftM Just arbitrary) ]
coarbitrary Nothing = variant 0
coarbitrary (Just a) = variant 1 . coarbitrary a
More information about the Haskell-Cafe