
10 May
2007
10 May
'07
9:46 a.m.
Hi
Would someone kindly explain why we need co-arbitrary in QuickCheck and how to define it?
To write your own 'coarbitrary', you are aiming to convert values of your datatype into a disjoint partition of the set of all Ints. In the end it is rather mechanical: e.g.
data Foo a = Foo String a | Bar Bool
instance Arbitrary (Foo a) where coarbitrary (Foo s a) = variant 0 . coarbitrary s . coarbitrary a coarbitrary (Bar b) = variant 1 . coarbitrary b
The Derive tool now implements coarbitrary for the instances it generates - following the scheme outlined in this email. http://www-users.cs.york.ac.uk/~ndm/derive/ Thanks Neil