On Nov 22, 2013, at 2:57 PM, Joseph Abrahamson <me@jspha.com> wrote:

I really like this idea, but I think I’d personally love to see some examples of it in practice. 75% of my Arbitrary instances are “traverse arbitrarily” and 95% of them keep Gen abstract, so I have a good feeling that it’d be possible to implement with relatively small amounts of user pain.

That's been my experience as well, though I haven't even had the 5% where I've had to break the Gen abstraction.


The thing I wonder about is how often `arbitrary` declarations provide enough information for efficient, meaningful `shrink` declarations. If the two differ it may be more necessary to break into `Gen` to provide the right kind of behavior—which would be increasingly complex.

My experience with both Erlang QuickCheck and simple-check (Clojure) is that it _is_ enough information. In the rare cases it's not, you can always still implement your own logic for shrinking by breaking the Gen abstraction (manipulating the RoseTree yourself).


I’d love to see some examples of complex generators from simple-check implemented in this style. As an ugly example I frequently run into in my own code, it’s often hard to write a good arbitrary instance for UTCTime—it’s very domain specific what defines a good arbitrary time. Would such kinds of complex generator code also lead to a nice shrink function? Or would it require something more complex?

 I think a powerful example is an 'any' generator I have in simple-check, which will generate arbitrary Clojure values [1]. It's constructed in exactly the same way as you'd do it with today's QuickCheck, but it also shrinks as well as a hand-written shrink algorithm. (I've found edge-cases in Clojure's reader/writer this way).

[1]  https://github.com/reiddraper/simple-check/blob/v0.5.3/src/simple_check/generators.clj#L525-L553