
Gen slightly breaks the monad laws:
arbitrary >>= return is not the same as return () >>= const arbitrary because each bind splits the generator, so you end up with a different seed passed to arbitrary in these two cases.
If the observable value is "some random object" this is a safe fudge,
but if you want repeatable, it doesn't quite work. You need your
instances to be exactly identical, down to the associativity of binds,
in order to get the same results.
-- ryan
On Tue, Feb 2, 2010 at 4:34 AM, Sean Leather
Correction about the latter part...
In the end, I would write something like the following:
unGen arbitrary (mkStdGen 11) 5 :: [Int]
This produces, for example, [5,1,-2,-4,2]. I also want to generate the same value for a type isomorphic to [Int].
unGen arbitrary (mkStdGen 11) 5 :: List Int
Unfortunately, this produces Cons 4 (Cons 3 (Cons (-2) (Cons 0 (Cons (-1) Nil)))): same length but different values. The Arbitrary instances are the same.
The Arbitrary instance were _slightly_ different, but different enough. ;) Now, the values are isomorphic. Thankfully, purity is restored.
Sean
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe