on master help sign in
Monoid instance for pattern
commitecf4c64f620db72495289f7bce182bf262dc4de4 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 5 Apr 2011, 11:50 (16 years ago) parentb7059a0
1 file changed+7−1
src/Hakyll/Core/Identifier/Pattern.hs+7−1
src/Hakyll/Core/Identifier/Pattern.hs+7−1
@@ -47,7 +47,7 @@ import Data.List (isPrefixOf, inits, tails)
4747import Control.Arrow ((&&&), (>>>))
4848import Control.Monad (msum)
4949import Data.Maybe (isJust)
50−import Data.Monoid (mempty, mappend)
50+import Data.Monoid (Monoid, mempty, mappend)
5151
5252import GHC.Exts (IsString, fromString)
5353
@@ -68,6 +68,12 @@ data Pattern = Glob [GlobComponent]
6868instance IsString Pattern where
6969 fromString = parseGlob
7070
71+instance Monoid Pattern where
72+ mempty = Predicate (const True)
73+ g@(Glob _) `mappend` x = Predicate (matches g) `mappend` x
74+ x `mappend` g@(Glob _) = x `mappend` Predicate (matches g)
75+ Predicate f `mappend` Predicate g = Predicate $ \i -> f i && g i
76+
7177-- | Parse a pattern from a string
7278--
7379parseGlob :: String -> Pattern