[Haskell-beginners] Why does QuickCheck insist on this class constraint?

martin martin.drautzburg at web.de
Mon Mar 30 11:22:44 UTC 2015


Hello all,

Ghc complainend about

    Could not deduce (Arbitrary a1) arising from a use of ‘arbitrary’
    Could not deduce (Eq a1) arising from a use of ‘arbitrary’

in the following code ..

data CList a = CList [Change a]
             deriving Show

instance (Arbitrary c, Eq c) => Arbitrary (CList c)
        where
            arbitrary = do
                ts <- orderedList      :: Gen[Time]
                vs <- listOf arbitrary :: Arbitrary c => Gen [c]
                return $ CList $ zipWith (\t v -> Chg t v) (nub ts) vs


instance (Arbitrary a, Eq a) => Arbitrary (Temporal a)
        where
            arbitrary = do
                d  <- arbitrary
                (CList cs) <- arbitrary :: (Arbitrary a, Eq a) => Gen (CList a) -- <===
                return (Temporal d cs)

..if I leave out the class constraints in the line maked with "<===". Why is that so, i.e. why isn't the constraint four
lines up (in the instance declaration) sufficient?


More information about the Beginners mailing list