You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and those would be really useful to generate for CoArbitrary, for sort predicates and such. However, the standard Arbitrary instance for them would not be useful, because they don't abide by the reflexivity, symmetry/antisymmetry, and transitivity laws at all.
However, I think I found a way. A CoArbitrary type can be sort of "hashed" by using it on a Gen:
cohash::CoArbitrarya=>QCGen->Int->a->Int
cohash g n a = unGen (coarbitrary a $MkGen$\g0 n0 ->fst$ randomR (negate n0, n0) g0) g n
Here, the "size" of the generator represents the "fineness" of the hash.
With that, we can generate the instances as follows:
instanceCoArbitrarya=>Arbitrary (Equivalencea) where
arbitrary =MkGen$\g n ->Equivalence$\a b -> cohash g n a == cohash g n b
instanceCoArbitrarya=>Arbitrary (Comparisona) where
arbitrary =MkGen$\g n ->Comparison$\a b ->compare (cohash g n a) (cohash g n b)
(Incidentally, the type Predicate also exists, but can be generated with the standard instance for a -> Bool.)
The text was updated successfully, but these errors were encountered:
(Copied from nick8325/quickcheck#280 )
Data.Functor.Contravariant
is now inbase
, and it includes the typesand those would be really useful to generate for
CoArbitrary
, for sort predicates and such. However, the standardArbitrary
instance for them would not be useful, because they don't abide by the reflexivity, symmetry/antisymmetry, and transitivity laws at all.However, I think I found a way. A
CoArbitrary
type can be sort of "hashed" by using it on aGen
:Here, the "size" of the generator represents the "fineness" of the hash.
With that, we can generate the instances as follows:
(Incidentally, the type
Predicate
also exists, but can be generated with the standard instance fora -> Bool
.)The text was updated successfully, but these errors were encountered: