{-# LANGUAGE GeneralizedNewtypeDeriving #-} import Test.QuickCheck import Test.QuickCheck.Function newtype ReversingList a = ReversingList [a] deriving (Show, Eq, Arbitrary) -- This ReversingList is a Functor instance that reverses the elements while it -- maps over them. instance Functor ReversingList where fmap f (ReversingList xs) = ReversingList (reverse (fmap f xs)) -- The functor law is that (fmap f . fmap g) == fmap (f . g). prop_functorLaw (Fun _ f) (Fun _ g) xs = (fmap f . fmap g) xs == fmap (f . g) xs where types = ( xs :: ReversingList Int , f :: Int -> Int , g :: Int -> Int ) main = quickCheck prop_functorLaw {- Output: *** Failed! Falsifiable (after 6 tests and 19 shrinks): {-5->1, _->0} {0->-5, _->0} ReversingList [1,0] -}