Folks,
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 .
coarbitrary a"?
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
Thanks, Joel
--
http://wagerlabs.com/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe