From ecf4c64f620db72495289f7bce182bf262dc4de4 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Tue, 5 Apr 2011 11:50:46 +0200 Subject: Monoid instance for pattern --- src/Hakyll/Core/Identifier/Pattern.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/Hakyll/Core') diff --git a/src/Hakyll/Core/Identifier/Pattern.hs b/src/Hakyll/Core/Identifier/Pattern.hs index 42f67f0..28e23ad 100644 --- a/src/Hakyll/Core/Identifier/Pattern.hs +++ b/src/Hakyll/Core/Identifier/Pattern.hs @@ -47,7 +47,7 @@ import Data.List (isPrefixOf, inits, tails) import Control.Arrow ((&&&), (>>>)) import Control.Monad (msum) import Data.Maybe (isJust) -import Data.Monoid (mempty, mappend) +import Data.Monoid (Monoid, mempty, mappend) import GHC.Exts (IsString, fromString) @@ -68,6 +68,12 @@ data Pattern = Glob [GlobComponent] instance IsString Pattern where fromString = parseGlob +instance Monoid Pattern where + mempty = Predicate (const True) + g@(Glob _) `mappend` x = Predicate (matches g) `mappend` x + x `mappend` g@(Glob _) = x `mappend` Predicate (matches g) + Predicate f `mappend` Predicate g = Predicate $ \i -> f i && g i + -- | Parse a pattern from a string -- parseGlob :: String -> Pattern -- cgit v1.2.3