Skip to content

Commit

Permalink
Function instances
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianAlgehed committed Mar 21, 2024
1 parent 04769c6 commit e126be2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Test/QuickCheck/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/Test/QuickCheck/Function.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e126be2

Please sign in to comment.