Skip to content

Commit

Permalink
Min and Max from Semigroup
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAlgehed committed Mar 21, 2024
1 parent e126be2 commit cae124f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/Test/QuickCheck/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ import System.IO
#if defined(MIN_VERSION_base)
#if MIN_VERSION_base(4,9,0)
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.Semigroup as Semigroup
#endif
#endif

Expand Down Expand Up @@ -1014,6 +1015,18 @@ instance Arbitrary a => Arbitrary (Monoid.Last a) where
shrink = map Monoid.Last . shrink . Monoid.getLast
#endif

#if defined(MIN_VERSION_base)
#if MIN_VERSION_base(4,9,0)
instance Arbitrary a => Arbitrary (Semigroup.Min a) where
arbitrary = fmap Semigroup.Min arbitrary
shrink = map Semigroup.Min . shrink . Semigroup.getMin

instance Arbitrary a => Arbitrary (Semigroup.Max a) where
arbitrary = fmap Semigroup.Max arbitrary
shrink = map Semigroup.Max . shrink . Semigroup.getMax
#endif
#endif

#if MIN_VERSION_base(4,8,0)
instance Arbitrary (f a) => Arbitrary (Monoid.Alt f a) where
arbitrary = fmap Monoid.Alt arbitrary
Expand Down Expand Up @@ -1584,6 +1597,15 @@ instance CoArbitrary a => CoArbitrary (Monoid.Last a) where
coarbitrary = coarbitrary . Monoid.getLast
#endif

#if MIN_VERSION_base(4,9,0)
instance CoArbitrary a => CoArbitrary (Semigroup.Min a) where
coarbitrary = coarbitrary . Semigroup.getMin

instance CoArbitrary a => CoArbitrary (Semigroup.Max a) where
coarbitrary = coarbitrary . Semigroup.getMax
#endif


#if MIN_VERSION_base(4,8,0)
instance CoArbitrary (f a) => CoArbitrary (Monoid.Alt f a) where
coarbitrary = coarbitrary . Monoid.getAlt
Expand Down
11 changes: 10 additions & 1 deletion src/Test/QuickCheck/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import GHC.Generics hiding (C)
#if defined(MIN_VERSION_base)
#if MIN_VERSION_base(4,9,0)
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.Semigroup as Semigroup
#endif
#endif

Expand Down Expand Up @@ -442,13 +443,21 @@ instance Function a => Function (Monoid.Last a) where
instance Function a => Function (Down a) where
function = functionMap (\(Down a) -> a) Down
#endif
#endif

#if MIN_VERSION_base(4,8,0)
instance Function (f a) => Function (Monoid.Alt f a) where
function = functionMap Monoid.getAlt Monoid.Alt
#endif

#if MIN_VERSION_base(4,9,0)
instance Function a => Function (Semigroup.Min a) where
function = functionMap Semigroup.getMin Semigroup.Min

instance Function a => Function (Semigroup.Max a) where
function = functionMap Semigroup.getMax Semigroup.Max
#endif
#endif

-- poly instances

instance Function A where
Expand Down

0 comments on commit cae124f

Please sign in to comment.