Skip to content

Commit

Permalink
Add Semigroup (Predicate a) instance (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej authored and RyanGlScott committed Jan 8, 2018
1 parent 80c0915 commit d9bac20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
_darcs
dist
dist-newstyle
.ghc.environment.*
9 changes: 9 additions & 0 deletions src/Data/Functor/Contravariant.hs
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,18 @@ newtype Predicate a = Predicate { getPredicate :: a -> Bool }
instance Contravariant Predicate where
contramap f g = Predicate $ getPredicate g . f

#if defined(MIN_VERSION_semigroups) || __GLASGOW_HASKELL__ >= 711
instance Semigroup (Predicate a) where
Predicate p <> Predicate q = Predicate $ \a -> p a && q a
#endif

instance Monoid (Predicate a) where
mempty = Predicate $ const True
#if defined(MIN_VERSION_semigroups) || __GLASGOW_HASKELL__ >= 711
mappend = (<>)
#else
mappend (Predicate p) (Predicate q) = Predicate $ \a -> p a && q a
#endif

-- | Defines a total ordering on a type as per 'compare'
--
Expand Down

0 comments on commit d9bac20

Please sign in to comment.