[Haskell-beginners] QuickCheck 2 entering infinite loop
Dominic Mulligan
dominic.p.mulligan at googlemail.com
Thu Jan 21 17:05:20 EST 2010
Dear all,
I'm trying to work out how to use QuickCheck 2 (installed via apt-get
from the Ubuntu repositories) and in the process keep managing to get
the quickCheck function (called under GHCi 6.10.4) to enter what appears
to be an infinite loop. Evidently, I'm doing something wrong ...
Here's the problem: I have a module for types, and it exports a datatype
called "Type". I make this an instance of Arbitrary, like so:
instance (Eq a, Arbitrary a) => Arbitrary (Type a) where
arbitrary = oneof [
liftM tyVar arbitrary,
liftM2 tyCon arbitrary arbitrary]
Here, tyVar and tyCon are two functions injecting into Types.
I then write two silly properties to test whether this works. The first
property:
prop_InjectTypeVarFreeVar var =
(freeTypeVars . tyVar) var == [tyVar var]
Works fine. A call to quickCheck gives me the familiar "100 tests
passed" message. The second property:
prop_InjectTypeConFreeVars args =
(freeTypeVars . (tyCon "Fun")) args == (concatMap freeTypeVars args)
Sends quickCheck into an infinite loop of some sort. It manages to get
through 5-6 tests before GHCi is brought to its knees. Before I go
crazy, can anybody explain what I'm doing wrong?
Many thanks in advance,
Dominic
More information about the Beginners
mailing list