[darcs-devel] [patch2166] cleaning up Arbitrary instances

Ganesh Sittampalam bugs at darcs.net
Thu Jun 3 12:33:21 UTC 2021


Ganesh Sittampalam <ganesh at earth.li> added the comment:

>>   * introduce Triple to reduce the random instance overlaps
> 
> OK, though it's not yet clear at this point if this addition amortizes.
> Also, you previously removed arbitraryTriple by generalizing the
> instance ArbitraryState (p :> p) to ArbitraryState (p :> q) which looks
> like a move in the opposite direction.

The patch that removed arbitraryTriple ("get rid of arbitraryTriple")
replaced both arbitraryTriple and instance ArbitraryState (p :> p) with
instance ArbitraryState (p :> q). arbitraryTriple had a comment above it:

> {- the type instance overlaps!
> type instance ModelOf (p :> p :> p) = ModelOf p
> 
> instance ArbitraryState p => ArbitraryState (p :> p :> p) where
> -}

My perspective is that the generic (p :> q) instance is simpler and more
compositional than having multiple instances for different sets of
arguments to (:>).

This particular patch introduced Triple to replace instance ArbitraryWS
(p :> p :> p), at the cost of some extra boilerplate. Again my goal was
to get to simpler more compositional instances, but I agree the
incremental benefit is less obvious here.

The combined effect is that there is just one instance for (:>) and one
instance for Triple. Overall the direction is to move the burden of
choosing how generation should work from a mess of overlapping instances
into something more type-driven at the sites where tests are defined.

> BTW, it is not easy to guess
> where the Pair type is defined (it's in D.T.P.WithState). A slightly
> longer comment explaining the where and how would have made sense here.

Agreed. When I first wrote these patches I was in exploratory mode, I
should probably have gone back and rebased them with better explanations
instead of submitting as-is.

__________________________________
Darcs bug tracker <bugs at darcs.net>
<http://bugs.darcs.net/patch2166>
__________________________________


More information about the darcs-devel mailing list