[Haskell-beginners] quickCheck generation question

Joe Van Dyk joe at fixieconsulting.com
Sat Oct 8 01:40:49 CEST 2011


I'm going through the 99 Haskell problems and am trying to write
quickCheck properties for each one.

-- 3 (find k"th element of a list)
element_at xs x = xs !! x
prop_3a xs x = (x < length xs && x >= 0) ==> element_at xs (x::Int) ==
(xs !! x::Int)

When I run prop_3a through quickCheck, it gives up, saying that it
only passed 1 test.  This makes sense, because the random x is going
to be larger than the number of elements in the random list in most
cases.

So what I need to do is write a generator that generates a random list
with length larger than a random integer, but I'm not sure how to do
that.

Thanks!
Joe



More information about the Beginners mailing list