[Generalized bestMatchings to return all matchings with a maximal number of closed rules (instead of only closed rules)
tobias@goedderz.info**20150304154357
 Ignore-this: 851c8bb5f9ca8577f0610d2aa83e3af3
] hunk ./src/Igor2/RuleDevelopment/Matching.hs 125
+{- This holds a *lower bound* on the maximum number of closed rules in
+ - bestMatchings'.
+ -}
+type StateMinClosedRules = StateT Int
+
hunk ./src/Igor2/RuleDevelopment/Matching.hs 131
-bestMatchings = bestMatchings' (LT, [])
+bestMatchings ioMatrix = evalStateT (bestMatchings' (LT, []) ioMatrix) 0
hunk ./src/Igor2/RuleDevelopment/Matching.hs 145
-               -> C MatchingErrorMonad [(Ordering, ArgList FunList)]
-bestMatchings' hist []       = do return [hist]
+               -> StateMinClosedRules (C MatchingErrorMonad) [(Ordering, ArgList FunList)]
+bestMatchings' hist [] =
+    do numClosedRules <- lift $ numClosedRulesOf (snd hist)
+       prevMaxClosedRules <- get
+       put (max numClosedRules prevMaxClosedRules)
+       return [hist]
hunk ./src/Igor2/RuleDevelopment/Matching.hs 153
-        let nhist = (max o *** multiCons rs) hist
-        in do allClosed <- liftM and $ mapM (liftM Rules.isClosed . lggRules) (snd nhist)
-              if allClosed
-                then bestMatchings' nhist xxs
-                else return []
+        do let nhist = (max o *** multiCons rs) hist
+           maxNumClosedRules <- lift $ numClosedRulesOf (snd nhist)
+           lowerBoundOnClosedRules <- get
+           if maxNumClosedRules >= lowerBoundOnClosedRules
+             then bestMatchings' nhist xxs
+             else return []
hunk ./src/Igor2/RuleDevelopment/Matching.hs 160
+
+numClosedRulesOf :: ArgList FunList -> C MatchingErrorMonad Int
+numClosedRulesOf = liftM length . filterM (liftM Rules.isClosed . lggRules)