From e126be20b38b891405e443b9ea16842840ea202b Mon Sep 17 00:00:00 2001 From: Maximilian Algehed Date: Thu, 21 Mar 2024 11:51:19 +0100 Subject: [PATCH] Function instances --- src/Test/QuickCheck/Arbitrary.hs | 1 - src/Test/QuickCheck/Function.hs | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Test/QuickCheck/Arbitrary.hs b/src/Test/QuickCheck/Arbitrary.hs index 9f4cee23..2ddfb7f7 100644 --- a/src/Test/QuickCheck/Arbitrary.hs +++ b/src/Test/QuickCheck/Arbitrary.hs @@ -1439,7 +1439,6 @@ instance CoArbitrary a => CoArbitrary (NonEmpty a) where #endif #endif - #ifndef NO_FIXED instance HasResolution a => CoArbitrary (Fixed a) where coarbitrary = coarbitraryReal diff --git a/src/Test/QuickCheck/Function.hs b/src/Test/QuickCheck/Function.hs index d8c0d27f..f2ef5f89 100644 --- a/src/Test/QuickCheck/Function.hs +++ b/src/Test/QuickCheck/Function.hs @@ -72,6 +72,7 @@ import Data.Char import Data.Word import Data.List( intersperse ) import Data.Ratio +import Data.Ord import qualified Data.IntMap as IntMap import qualified Data.IntSet as IntSet import qualified Data.Map as Map @@ -101,6 +102,12 @@ import Data.Fixed import GHC.Generics hiding (C) #endif +#if defined(MIN_VERSION_base) +#if MIN_VERSION_base(4,9,0) +import Data.List.NonEmpty (NonEmpty(..)) +#endif +#endif + -------------------------------------------------------------------------- -- concrete functions @@ -261,6 +268,13 @@ instance Function a => Function [a] where h (Left _) = [] h (Right (x,xs)) = x:xs +#if defined(MIN_VERSION_base) +#if MIN_VERSION_base(4,9,0) +instance Function a => Function (NonEmpty a) where + function = functionMap (\(a :| as) -> (a, as)) (uncurry (:|)) +#endif +#endif + instance Function a => Function (Maybe a) where function = functionMap g h where @@ -423,6 +437,13 @@ instance Function a => Function (Monoid.First a) where instance Function a => Function (Monoid.Last a) where function = functionMap Monoid.getLast Monoid.Last +#if defined(MIN_VERSION_base) +#if MIN_VERSION_base(4,6,0) +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