[Haskell-cafe] How to generate dependend values with QuickCheck
Jürgen Nicklisch-Franken
jnf at arcor.de
Thu Aug 26 00:14:10 EDT 2010
Thank you all, (you are responding so quick that I consider to stop
thinking myself in the future and just ask).
Jürgen
Am Donnerstag, den 26.08.2010, 00:02 -0400 schrieb Edward Z. Yang:
> Excerpts from Jürgen Nicklisch-Franken's message of Wed Aug 25 23:32:51 -0400 2010:
> > instance Arbitrary QCExample where
> > arbitrary =
> > let i1 = arbitrary
> > i2 = fmap (* 2) i1
> > in liftM2 QCExample i1 i2
>
> What's happening here is that you are "evaluating" the random value generator
> too late in the game: when you set i1 = arbitrary, no random value has been
> generated yet, and i2 is thus another generator which has no relation to
> what i1 might produce. You could instead do this:
>
> arbitrary = do
> i1 <- arbitrary
> let i2 = i1 * 2
> return (QCExample i1 i2)
>
> Cheers,
> Edward
More information about the Haskell-Cafe
mailing list