`coarbitrary' is not a (visible) method of class `Arbitrary'

I'm trying to follow the instructions in http://haskell.org/haskellwiki/How_to_write_a_Haskell_program. I'm at the step where we've just written a QuickCheck test: amy@localhost ~/forbairt/haq $ cat Tests.hs import Char import List import Test.QuickCheck import Text.Printf main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests instance Arbitrary Char where arbitrary = choose ('\0', '\128') coarbitrary c = variant (ord c `rem` 4) -- reversing twice a finite list, is the same as identity prop_reversereverse s = (reverse . reverse) s == id s where _ = s :: [Int] -- and add this to the tests list tests = [("reverse.reverse/id", test prop_reversereverse)] But when I try to run it, I get the following errors: amy@localhost ~/forbairt/haq $ runhaskell Tests.hs Tests.hs:10:4: `coarbitrary' is not a (visible) method of class `Arbitrary' Tests.hs:17:33: Not in scope: `test' I think this has something to do with the changes between QuickCheck v1 and v2. Can someone tell me what I need to do to make this example work? Thank you in advance! Amy

Am Samstag 19 Dezember 2009 14:20:43 schrieb Amy de Buitléir:
I'm trying to follow the instructions in http://haskell.org/haskellwiki/How_to_write_a_Haskell_program. I'm at the step where we've just written a QuickCheck test:
amy@localhost ~/forbairt/haq $ cat Tests.hs import Char import List import Test.QuickCheck import Text.Printf
main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests
instance Arbitrary Char where arbitrary = choose ('\0', '\128') coarbitrary c = variant (ord c `rem` 4)
-- reversing twice a finite list, is the same as identity prop_reversereverse s = (reverse . reverse) s == id s where _ = s :: [Int]
-- and add this to the tests list tests = [("reverse.reverse/id", test prop_reversereverse)]
But when I try to run it, I get the following errors:
amy@localhost ~/forbairt/haq $ runhaskell Tests.hs
Tests.hs:10:4: `coarbitrary' is not a (visible) method of class `Arbitrary'
Tests.hs:17:33: Not in scope: `test'
I think this has something to do with the changes between QuickCheck v1 and v2.
Yes. coarbitrary has moved to its own class, CoArbitrary. Now there's also method shrink in Arbitrary. There is already an instance Arbitrary Char in QC 2, as well as instance CoArbitrary Char. In QC 1, test was a synonym for quickCheck, so why not use quickCheck?
Can someone tell me what I need to do to make this example work? Thank you in advance!
Amy
HTH, Daniel

Thank you Daniel, that solved it. In case anyone else is struggling with this, here's a revised version of Test.hs which works fine for me. import Char import List import Test.QuickCheck import Text.Printf main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests -- reversing twice a finite list, is the same as identity prop_reversereverse s = (reverse . reverse) s == id s where _ = s :: [Int] -- and add this to the tests list tests = [("reverse.reverse/id", quickCheck prop_reversereverse)]

Am Samstag 19 Dezember 2009 15:30:10 schrieb Amy de Buitléir:
import Char import List
The wrappers around the pre-hierarchical-modules standard libraries may not be around forever, so it's better to get used to import Data.Char import Data.List before they're gone.
participants (2)
-
Amy de Buitléir
-
Daniel Fischer