@@ -111,22 +111,33 @@ prop_Word32_from_2_Word16 w1 w2 = property $
111111 w0 = ((fromIntegral w1) `shiftL` 16) .|. fromIntegral w2
112112-}
113113
114+
115+shrinker :: (Num a, Ord a, Bits a) => a -> [a]
116+shrinker 0 = []
117+shrinker w = [ w `shiftR` 1 -- try to make everything roughly half size
118+ ] ++ [ w' -- flip bits to zero, left->right
119+ | m <- [n, n-1..1]
120+ , let w' = w `clearBit` m
121+ , w /= w'
122+ ] ++ [w-1] -- just make it a little smaller
123+ where
124+ n = bitreq w
125+
114126instance Arbitrary Word8 where
115127 arbitrary = choose (minBound, maxBound)
116− shrink 0 = []
117− shrink n = [ n - 1 ]
128+ shrink = shrinker
118129
119130instance Arbitrary Word16 where
120131 arbitrary = choose (minBound, maxBound)
121− shrink 0 = []
122− shrink n = [ n - 10000, n - 1000, n - 100, n - 1 ]
132+ shrink = shrinker
123133
124134instance Arbitrary Word32 where
125135 arbitrary = choose (minBound, maxBound)
136+ shrink = shrinker
126137
127138instance Arbitrary Word64 where
128139 arbitrary = choose (minBound, maxBound)
129−
140+ shrink = shrinker
130141
131142integralRandomR :: (Integral a, RandomGen g) => (a,a) -> g -> (a,g)
132143integralRandomR (a,b) g = case randomR (fromIntegral a :: Integer,