
Hello All,
I am asking help with using QuickCheck. I tried everything I could think
of, but invariably as soon as I start invoking the quickCheck function
on my property it fails with
*Data.FingerSearchTreeUtil>
Top level:
No instance for (Show (IO ()))
arising from use of `print' at Top level
Probable fix: add an instance declaration for (Show (IO ()))
In a 'do' expression: print it
<interactive>:1:0:
No instances for (Arbitrary (OrdSeq Int), Show (OrdSeq Int))
arising from use of `quickCheck' at <interactive>:1:0-20
Probable fix:
add an instance declaration for (Arbitrary (OrdSeq Int), Show
(OrdSeq Int))
In the definition of `it': it = quickCheck prop_DeleteInsert
The property is quite a simple one:
prop_DeleteInsert x xs = delete x (insert x xs) == xs
where types = xs :: OrdSeq Int
My code compiles just fine with ghc. I tried some examples from the
QuickCheck manual and these seem to work; at least I get the expected
"OK, passed 100 tests.".
What am I doing wrong?
Besides, there are some really non-obvious quirks with QuickCheck. For
instance, the following one caused me some headache:
I downloaded the haskell script 'quickCheck' and modified the line where
ghci is executed like this:
system ("/usr/bin/ghci -cpp -package QuickCheck "++options opts'++"

Benjamin Franksen wrote:
I am asking help with using QuickCheck. I tried everything I could think of, but invariably as soon as I start invoking the quickCheck function on my property it fails with
No instances for (Arbitrary (OrdSeq Int), Show (OrdSeq Int))
You need to define an `instance Arbitrary (OrdSeq Int)' for QuickCheck to be able to generate test data. `instance Show (OrdSeq Int)' is needed so the offending example can be reported to you in case some test fails. You should believe your compiler when it tells you
add an instance declaration for (Arbitrary (OrdSeq Int), Show (OrdSeq Int))
;-)
"No instance for (Show (IO ()))..."
I think, this is an artefact of unresolved overloading or missing instances. Somehow GHCi attaches an unnecessary implicit `print'. When I played with QuickCheck, this error went away as soon as the rest of the expression type checked. Udo. -- Life is Hard, But Life is Harder When You're Dumb. -- The Austin Lounge Lizards

On Friday 21 October 2005 20:14, Udo Stenzel wrote:
Benjamin Franksen wrote:
I am asking help with using QuickCheck. I tried everything I could think of, but invariably as soon as I start invoking the quickCheck function on my property it fails with
No instances for (Arbitrary (OrdSeq Int), Show (OrdSeq Int))
You need to define an `instance Arbitrary (OrdSeq Int)' for QuickCheck to be able to generate test data. `instance Show (OrdSeq Int)' is needed so the offending example can be reported to you in case some test fails. You should believe your compiler when it tells you
add an instance declaration for (Arbitrary (OrdSeq Int), Show (OrdSeq Int))
;-)
"No instance for (Show (IO ()))..."
I think, this is an artefact of unresolved overloading or missing instances. Somehow GHCi attaches an unnecessary implicit `print'. When I played with QuickCheck, this error went away as soon as the rest of the expression type checked.
Many thanks! I wish I had remembered that I had this kind of problem before: ghc reports two errors, of which the /second/ one is the 'real' problem and the first one is just a by-product. This practically never happens with C compilers which I (must, sadly) use every day and thus I always tend to disregard all error messages but the first. And now as I think of it, it would indeed be quite hard for QuickCheck to guess hwo to generate my OrdSeqs. Ben

On Fri, Oct 21, 2005 at 09:09:41PM +0200, Benjamin Franksen wrote:
Many thanks! I wish I had remembered that I had this kind of problem before: ghc reports two errors, of which the /second/ one is the 'real' problem and the first one is just a by-product.
The case in your original message is particularly annoying, but at least it only affects ghci. I thought it had been fixed[1], but it is still present in 6.4.1, so perhaps it's waiting for 6.5?
This practically never happens with C compilers which I (must, sadly) use every day and thus I always tend to disregard all error messages but the first.
I generally find that most of GHC's errors are real, ie they don't change much when I fix earlier errors. (It seems to report only one error per function to achieve that?) It's fun to work through the dozen reported mistakes, then compile again to see how many I actually fixed. :-) Andrew [1] http://sourceforge.net/tracker/index.php?func=detail&aid=1156554&group_id=8032&atid=108032

On Friday 21 October 2005 21:45, Andrew Pimlott wrote:
On Fri, Oct 21, 2005 at 09:09:41PM +0200, Benjamin Franksen wrote:
Many thanks! I wish I had remembered that I had this kind of problem before: ghc reports two errors, of which the /second/ one is the 'real' problem and the first one is just a by-product.
The case in your original message is particularly annoying, but at least it only affects ghci. I thought it had been fixed[1], but it is still present in 6.4.1, so perhaps it's waiting for 6.5?
This practically never happens with C compilers which I (must, sadly) use every day and thus I always tend to disregard all error messages but the first.
I generally find that most of GHC's errors are real, ie they don't change much when I fix earlier errors. (It seems to report only one error per function to achieve that?) It's fun to work through the dozen reported mistakes, then compile again to see how many I actually fixed.
Yes, normally the error messages from ghc are very good and useful. It happens only rarely that some error message is completely opaque to me and then my brain auto-switches to "ignore everything but the first message" mode -- which works great in C but in Haskell sometimes leads me completely astray... Ben

On Fri, Oct 21, 2005 at 07:58:10PM +0200, Benjamin Franksen wrote:
I am asking help with using QuickCheck. I tried everything I could think of, but invariably as soon as I start invoking the quickCheck function on my property it fails with
<interactive>:1:0: No instances for (Arbitrary (OrdSeq Int), Show (OrdSeq Int)) arising from use of `quickCheck' at <interactive>:1:0-20 Probable fix: add an instance declaration for (Arbitrary (OrdSeq Int), Show (OrdSeq Int)) In the definition of `it': it = quickCheck prop_DeleteInsert
The property is quite a simple one:
prop_DeleteInsert x xs = delete x (insert x xs) == xs where types = xs :: OrdSeq Int
My code compiles just fine with ghc.
It compiles (and runs) fine as a function on OrdSeqs, with type prop_DeleteInsert :: Int -> OrdSeq Int -> Bool But as an argument to quickCheck, it needs be in the class Testable, which boils down to the requirement that Int and "OrdSeq Int" are both in the class Arbitrary. So you need to write something like instance Arbitrary a => Arbitrary (OrdSeq a) where ... This is confusing because QuickCheck is clever with type classes to check "ordinary" boolean functions. But in fact, your property is equivalent to prop_DeleteInsert = forall arbitrary $ \x -> forall arbitrary $ \xs -> delete x (insert x xs) == (xs :: OrdSeq Int) And QuickCheck doesn't know how to create arbitrary OrdSeqs unless you tell it.
I downloaded the haskell script 'quickCheck' and modified the line where ghci is executed like this:
system ("/usr/bin/ghci -cpp -package QuickCheck "++options opts'++"
(I am using ghc 6.4.1, btw). Running 'quickCheck Data/FingerSearchTreeUtil.hs' gives me:
<interactive>:1:0: Failed to load interface for `QuickCheck': Could not find module `QuickCheck': it is a member of package util-1.0, which is hidden
Strange. Replacing 'ChickCheck' with 'util' gives me the above error message about "No instance for (Show (IO ()))..."
In package QuickCheck, the module is called "Test.QuickCheck" (so "import Test.QuickCheck"), whereas in package util, it is called just "QuickCheck" (but this is deprecated). Andrew

On Friday 21 October 2005 20:24, Andrew Pimlott wrote:
On Fri, Oct 21, 2005 at 07:58:10PM +0200, Benjamin Franksen wrote:
I am asking help with using QuickCheck. I tried everything I could think of, but invariably as soon as I start invoking the quickCheck function on my property it fails with
<interactive>:1:0: No instances for (Arbitrary (OrdSeq Int), Show (OrdSeq Int)) arising from use of `quickCheck' at <interactive>:1:0-20 Probable fix: add an instance declaration for (Arbitrary (OrdSeq Int), Show (OrdSeq Int)) In the definition of `it': it = quickCheck prop_DeleteInsert
The property is quite a simple one:
prop_DeleteInsert x xs = delete x (insert x xs) == xs where types = xs :: OrdSeq Int
My code compiles just fine with ghc.
It compiles (and runs) fine as a function on OrdSeqs, with type
prop_DeleteInsert :: Int -> OrdSeq Int -> Bool
But as an argument to quickCheck, it needs be in the class Testable, which boils down to the requirement that Int and "OrdSeq Int" are both in the class Arbitrary. So you need to write something like
instance Arbitrary a => Arbitrary (OrdSeq a) where ...
This is confusing because QuickCheck is clever with type classes to check "ordinary" boolean functions. But in fact, your property is equivalent to
prop_DeleteInsert = forall arbitrary $ \x -> forall arbitrary $ \xs -> delete x (insert x xs) == (xs :: OrdSeq Int)
And QuickCheck doesn't know how to create arbitrary OrdSeqs unless you tell it.
Yes, now as you say it it seems quite obvious. I was mislead by the other error message, which I took to be the more important one, because it appeared first. Bad habits...
I downloaded the haskell script 'quickCheck' and modified the line where ghci is executed like this:
system ("/usr/bin/ghci -cpp -package QuickCheck "++options opts'++"
(I am using ghc 6.4.1, btw). Running 'quickCheck Data/FingerSearchTreeUtil.hs' gives me:
<interactive>:1:0: Failed to load interface for `QuickCheck': Could not find module `QuickCheck': it is a member of package util-1.0, which is hidden
Strange. Replacing 'ChickCheck' with 'util' gives me the above error message about "No instance for (Show (IO ()))..."
In package QuickCheck, the module is called "Test.QuickCheck" (so "import Test.QuickCheck"), whereas in package util, it is called just "QuickCheck" (but this is deprecated).
Thanks a lot for this explanation! Taking a look at the script, I see "QuickCheck.quickCheck" being written to the program that ghci gets as input. Changing it to "Test.QuickCheck.quickCheck" indeed fixes the problem. Thanks everyone for helping, Ben
participants (3)
-
Andrew Pimlott
-
Benjamin Franksen
-
Udo Stenzel