Suppose, I want to test the following associativity property for Sum
with the help of hedgehog library in Haskell:
a <> (b <> c) ≡ (a <> b) <> c
I have actually two ways to generate random input.
Gen
(using Gen
's Applicative and Monad instances)genTriple :: Get (Int, Int, Int)
genTriple = liftA3 (,,) Gen.enumBounded Gen.enumBounded Gen.enumBounded
prop_assoc :: Property
prop_assoc = property $ do
(a, b, c) <- forAll genTriple
(Sum a <> Sum b) <> Sum c === Sum a <> (Sum b <> Sum c)
forAll
prop_assoc :: Property
prop_assoc = property $ do
a <- forAll Gen.enumBounded
b <- forAll Gen.enumBounded
c <- forAll Gen.enumBounded
(Sum a <> Sum b) <> Sum c === Sum a <> (Sum b <> Sum c)
I wonder, what is the difference between two approaches? Does it somehow affect performance or parallelization or randomness?
Package maintainers answered this question under corresponding GitHub issue: