[Haskell-cafe] Re: Generating repeatable arbitrary values with
ryani.spam at gmail.com
Tue Feb 2 13:48:55 EST 2010
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.
On Tue, Feb 2, 2010 at 4:34 AM, Sean Leather <leather at cs.uu.nl> wrote:
> 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
> The Arbitrary instance were _slightly_ different, but different enough. ;)
> Now, the values are isomorphic. Thankfully, purity is restored.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe