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
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to