graph-rewriting 0.7.0 → 0.7.1
raw patch · 2 files changed
+27/−4 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ GraphRewriting.Rule: apply' :: Rule n -> Rewrite n Bool
+ GraphRewriting.Rule: benchmark :: [Rule n] -> Rewrite n [Int]
Files
- GraphRewriting/Rule.hs +26/−3
- graph-rewriting.cabal +1/−1
GraphRewriting/Rule.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE UnicodeSyntax, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, FlexibleContexts #-}+{-# LANGUAGE UnicodeSyntax, FlexibleInstances, FlexibleContexts #-} -- | Rewrite rules are represented as nested monads: a 'Rule' is a 'Pattern' that returns a 'Rewrite' the latter directly defining the transformation of the graph. -- -- For rule construction a few functions a provided: The most basic one is 'rewrite'. But in most cases 'erase', 'rewire', and 'replace*' should be more convenient. These functions express rewrites that /replace/ the matched nodes of the 'Pattern', which comes quite close to the @L -> R@ form in which graph rewriting rules are usually expressed.@@ -23,9 +23,15 @@ -- | Apply rule at an arbitrary position if applicable apply ∷ Rule n → Rewrite n ()-apply r = do+apply = void . apply'++-- | Apply rule at an arbitrary position. Return value states whether the rule was applicable.+apply' ∷ Rule n → Rewrite n Bool+apply' r = do contractions ← evalPattern r <$> ask- when (not $ null contractions) (head contractions >> return ())+ if null contractions+ then return False+ else head contractions >> return True -- rule construction --------------------------------------------------------- @@ -115,3 +121,20 @@ everywhere r = do ms ← amnesia $ matches r exhaustive $ restrictOverlap (\hist future → future ∈ ms) r++-- TODO: how lazy is this? can it be done lazier?+-- | Repeatedly apply the rules from the given list prefering earlier entries.+-- Returns a list of indexes reporting the sequence of rules that has applied.+benchmark ∷ [Rule n] → Rewrite n [Int]+benchmark rules = rec where++ rec = do+ contractions ← evalPattern (anyOf indexedRules) <$> ask+ case contractions of+ [] → return []+ (i,rw) : _ → fmap (i:) (rw >> rec)++ indexedRules = zipWith addIndex [0..] rules where+ addIndex i rule = do+ rw ← rule+ return (i, rw)
graph-rewriting.cabal view
@@ -1,5 +1,5 @@ Name: graph-rewriting-Version: 0.7.0+Version: 0.7.1 Copyright: (c) 2010, Jan Rochel License: BSD3 License-File: LICENSE