module Validation where import Data.Semigroup import Test.QuickCheck (arbitrary, Arbitrary(..), frequency) data Validation a b = Failure a | Success b deriving (Eq, Show) instance Semigroup a => Semigroup (Validation a b) where (Success x) <> _ = Success x _ <> (Success x) = Success x (Failure x) <> (Failure y) = Failure $ x <> y instance (Arbitrary a, Arbitrary b) => Arbitrary (Validation a b) where arbitrary = do x <- arbitrary y <- arbitrary frequency [ (1, return $ Success x), (1, return $ Failure y) ]