module Sum where import Test.QuickCheck import Test.QuickCheck.Checkers data Sum a b = First a | Second b deriving (Eq, Show) instance Functor (Sum a) where fmap f (First x) = First x fmap f (Second x) = Second $ f x instance Applicative (Sum a) where pure x = Second x First f <*> _ = First f Second f <*> x = fmap f x instance Monad (Sum a) where return = pure (First x) >>= f = First x (Second x) >>= f = f x instance (Arbitrary a, Arbitrary b) => Arbitrary (Sum a b) where arbitrary = frequency [ (1, fmap First arbitrary) , (1, fmap Second arbitrary) ] instance (Eq a, Eq b) => EqProp (Sum a b) where (=-=) = eq