[Haskell-cafe] Generating repeatable arbitrary values with QuickCheck 2

Sean Leather leather at cs.uu.nl
Mon Feb 1 16:54:23 EST 2010


I would like to generate an arbitrary (large) value to benchmark the
performance of constructing that value with isomorphic types. It seems like
QuickCheck might be useful in this regards. Has anyone done something
similar?

In versions 1.*, there was a generate function:

generate :: Int -> StdGen -> Gen a -> a
> generate n rnd (Gen m) = m size rnd'
>    where (size, rnd') = randomR (0, n) rnd
>

That seems to have disappeared in versions 2.*, and I didn't find a clear
replacement. I came up with using the destructor for Gen:

unGen :: Gen a -> StdGen -> Int -> a
>

The function generate seems to have a little something extra, though I'm not
sure if it's necessary. Is this true, or should I write an equivalent
generate function? As an aside, it would be nice to have a generate function
in the library, even if it is only a wrapper for unGen.

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. I had similar results with generate from QC 1.

Any suggestions on how to do this? With another library perhaps?

Thanks,
Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100201/796cb597/attachment.html


More information about the Haskell-Cafe mailing list