Given the following test code using QuickCheck, I would expect that prop_Max errMax
should fail as the definition of errMax
is incorrect.
This happens when I use the given signature for prop_Max
with the concrete type Int
. However when I give it the more polymorphic commented-out type using Ord
, the test passes. Why is this?
import Test.QuickCheck
myMax :: Ord a => a -> a -> a
myMax x y
|x > y = x
|otherwise = y
errMax :: Ord a => a -> a -> a
errMax x y
|x > y = y
|otherwise = x
-- prop_Max :: Ord a => (a -> a -> a) -> a -> a -> Bool
prop_Max :: (Int -> Int -> Int) -> Int -> Int -> Bool
prop_Max maxFunc x y = (x <= maxFunc x y) && (y <= maxFunc x y)
-- in ghci
-- quickCheck (prop_Max max)
-- quickCheck (prop_Max myMax)
-- quickCheck (prop_Max errMax)
prop_Max::Ord a=>(a->a->a)->a->a->Bool
, then, quickCheck (prop_Max errMax) will pass the test – Alaya