-- QuickCheck experiments/play module Main where import Test.QuickCheck import Control.Monad newtype Int' = Int' {unInt' :: Int} deriving (Eq,Ord,Show) prop_IsEven :: Int -> Bool prop_IsEven = even prop_IsEven' :: Int' -> Bool prop_IsEven' = even . unInt' q0 = quickCheck (\x -> prop_IsEven x) q0b = quickCheck (\x -> collect x $ prop_IsEven x) q1 = quickCheck (\x -> not (odd x) ==> prop_IsEven x) q1b = quickCheck (\x -> not (odd x) ==> collect x $ prop_IsEven x) q2 = quickCheck (\x -> not (odd $ unInt' x) ==> prop_IsEven' x) q2b = quickCheck (\x -> not (odd $ unInt' x) ==> collect x $ prop_IsEven' x) genEven1 :: Gen Int genEven1 = do i <- arbitrary return (i*2) genEven2 :: Gen Int genEven2 = frequency $ zip (iterate (2*) 1) $ map return $ reverse l where l = [2,4..20] len = length l q3 = quickCheck (forAll genEven2 (\x -> not (odd x) ==> collect x $ prop_IsEven x)) instance Arbitrary Int' where arbitrary = fmap Int' genEven2 {- instance Arbitrary Int' where arbitrary = oneof $ map (return . Int') [2,4..10] instance Arbitrary Int' where arbitrary = liftM Int' arbitrary instance Arbitrary Int' where arbitrary = do i <- arbitrary return (Int' i) -} main = q2b