[Haskell-cafe] Re: class Arbitrary in quickcheck

Tim Docker twd2 at dockerz.net
Wed May 5 19:43:51 EDT 2010


On May 5, 10:57 pm, Ozgur Akgun <ozgurak... at gmail.com> wrote:
> Let me try to understand you then. What happens when you run the following
> command in ghci?
>
> sample (arbitrary :: Gen (Maybe Int, Maybe Int) )
>
> Do you still always get (Just _, Just _) or (Nothing, Nothing) pairs, or do
> you also get some (Nothing, Just _) or (Just _, Nothing) pairs?

Well, I couldn't run the above code, as "sample" isn't part of
quickcheck-1.2.
But this made me wonder whether it's a  version issue. This seems to
be the case. If I run this with quickcheck 2.1:

> import Test.QuickCheck
>
> main = quickCheckWith stdArgs{maxSuccess=100000} f
>
> f :: (Maybe Int,Maybe Int) -> Bool
> f (Just _,Just _) = True
> f (Nothing,Nothing) = True
> f _ = False

I see a failure almost instantly. This is what I want... I don't
expect all
of the generated pairs to have the same constructor in each field.

However, running this with quickcheck 1.2:

> import Test.QuickCheck
>
> main = quickCheckWith stdArgs{maxSuccess=100000} f
>
> f :: (Maybe Int,Maybe Int) -> Bool
> f (Just _,Just _) = True
> f (Nothing,Nothing) = True
> f _ = False

I see no failures... all of the generatd pairs have the same
constructor in each
field.

So the good news is that quickcheck 2.1 behaves as I expected. I'm
still curious
as to the behaviour of the older version.

Tim






More information about the Haskell-Cafe mailing list