blob: 382179bda80e66f87817aa5827f413daeec23150 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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]
-}
|