diff options
Diffstat (limited to 'qcheck.hs')
-rw-r--r-- | qcheck.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/qcheck.hs b/qcheck.hs new file mode 100644 index 0000000..382179b --- /dev/null +++ b/qcheck.hs @@ -0,0 +1,30 @@ +{-# 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] + +-} |