[Re-use partially evaluated lggs to safe some runtime
tobias@goedderz.info**20150304155112
 Ignore-this: 517e0b8416e5450ec6d3181b840de85d
] hunk ./src/Igor2/RuleDevelopment/Matching.hs 131
-bestMatchings ioMatrix = evalStateT (bestMatchings' (LT, []) ioMatrix) 0
+bestMatchings ioMatrix = evalStateT (bestMatchings' (LT, []) [] ioMatrix) 0
hunk ./src/Igor2/RuleDevelopment/Matching.hs 144
+               -> ArgList Rule
hunk ./src/Igor2/RuleDevelopment/Matching.hs 147
-bestMatchings' hist [] =
-    do numClosedRules <- lift $ numClosedRulesOf (snd hist)
-       prevMaxClosedRules <- get
-       put (max numClosedRules prevMaxClosedRules)
+bestMatchings' hist lggs [] =
+    do let numClosedRules = length $ filter Rules.isClosed lggs
+       -- Set the state to numClosedRules if numClosedRules is larger.
+       modify (max numClosedRules)
hunk ./src/Igor2/RuleDevelopment/Matching.hs 152
-bestMatchings' hist (xs:xxs) =
+bestMatchings' hist lggs (xs:xxs) =
hunk ./src/Igor2/RuleDevelopment/Matching.hs 155
-           maxNumClosedRules <- lift $ numClosedRulesOf (snd nhist)
-           lowerBoundOnClosedRules <- get
-           if maxNumClosedRules >= lowerBoundOnClosedRules
-             then bestMatchings' nhist xxs
-             else return []
+           nlggs <- lift $ nextLgg lggs rs
+           let maxNumClosedRules = length $ filter Rules.isClosed nlggs
+           violatesLowerBound <- gets (> maxNumClosedRules)
+           if violatesLowerBound
+             then return []
+             else bestMatchings' nhist nlggs xxs
hunk ./src/Igor2/RuleDevelopment/Matching.hs 166
-{-| This is nearly like zipWith (:), except when the two arguments don't have
+{-| multiCons is a helper function for bestMatchings'.
+
+    It works nearly like zipWith (:), except when the two arguments don't have
hunk ./src/Igor2/RuleDevelopment/Matching.hs 172
+
+    This is only intended for the case where the second argument is [].
+    Otherwise, both lists should always have the same length.
hunk ./src/Igor2/RuleDevelopment/Matching.hs 181
+{-| nextLgg is a helper function for bestMatchings'.
+
+    As the type anti-unifier doesn't handle "forall a. a" as a neutral element
+    during anti-unification, bestMatchings just passes an empty list of lggs,
+    and nextLgg handles this case by just returning its second argument.
+-}
+nextLgg :: [Rule] -> [Rule] -> C MatchingErrorMonad [Rule]
+nextLgg []   rs = return rs
+nextLgg lggs rs = zipWithM (\x y -> lggRules [x, y]) rs lggs
+