summaryrefslogtreecommitdiff
path: root/Utility/Matcher.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-09-18 17:47:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-09-18 17:47:24 -0400
commit38c0f3eaf86b67d584d4ff30ab15ec2c725a7fad (patch)
tree154125db67a2bc31eb37fa9923a4d55a533a3bec /Utility/Matcher.hs
parent3e15187ac1082bb086c79109c8b35dd8c20017ab (diff)
add a value to match against to match and matchM
Diffstat (limited to 'Utility/Matcher.hs')
-rw-r--r--Utility/Matcher.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/Utility/Matcher.hs b/Utility/Matcher.hs
index 0f589ec2c..08534fc30 100644
--- a/Utility/Matcher.hs
+++ b/Utility/Matcher.hs
@@ -17,9 +17,10 @@
module Utility.Matcher (
Token(..),
+ Matcher,
generate,
match,
- run
+ matchM
) where
import Control.Monad
@@ -62,21 +63,21 @@ consume m ((Token t):ts)
{- Checks if a Matcher matches, using a supplied function to check
- the value of Operations. -}
-match :: (op -> Bool) -> Matcher op -> Bool
-match a = go
+match :: (op -> v -> Bool) -> Matcher op -> v -> Bool
+match a m v = go m
where
go Any = True
go (And m1 m2) = go m1 && go m2
go (Or m1 m2) = go m1 || go m2
go (Not m1) = not (go m1)
- go (Op v) = a v
+ go (Op o) = a o v
{- Runs a monadic Matcher, where Operations are actions in the monad. -}
-run :: Monad m => Matcher (m Bool) -> m Bool
-run = go
+matchM :: Monad m => Matcher (v -> m Bool) -> v -> m Bool
+matchM m v = go m
where
go Any = return True
go (And m1 m2) = liftM2 (&&) (go m1) (go m2)
go (Or m1 m2) = liftM2 (||) (go m1) (go m2)
go (Not m1) = liftM not (go m1)
- go (Op o) = o -- run o
+ go (Op o) = o v