[allow rules matcher to look inside arguments
John Meacham <john@repetae.net>**20060210145308] hunk ./E/Rules.hs 182
--- applyRules :: ARules -> [E] -> IO (Maybe (E,[E]))
-applyRules (ARules rs) xs = f rs where
+applyRules lup (ARules rs) xs = f rs where
hunk ./E/Rules.hs 186
-    --f (r:_) | Just ss <- sequence (zipWith unify (ruleArgs r) xs) = ans ss where
-    f (r:rs) = case sequence (zipWith (match (ruleBinds r)) (ruleArgs r) xs) of
+    f (r:rs) = case sequence (zipWith (match lup (ruleBinds r)) (ruleArgs r) xs) of
hunk ./E/Rules.hs 192
-            {-
-            liftIO $ do
-                putStrLn "rule didn't match:"
-                printRule r
-                putDocMLn CharIO.putStr (hsep (map (parens . pprint) xs))
-                putStrLn err
-            f rs
-            -}
+
hunk ./E/SSimplify.hs 462
+        | Just (_x :: ARules) <- Info.lookup (tvrInfo x) = True
hunk ./E/SSimplify.hs 465
-    applyRule v xs  = do
+    applyRule v xs inb  = do
hunk ./E/SSimplify.hs 467
+        let lup x = case Map.lookup x (envInScope inb) of
+                Just (IsBoundTo _ e) -> Just e
+                _ -> Nothing
hunk ./E/SSimplify.hs 471
-            Nothing | fopts FO.Rules -> do
-                applyRules (Info.fetch (tvrInfo v)) xs
-                --case z of
-                --    Just (x,xs) -> app (x,xs)
-                --    Nothing -> return Nothing
+            Nothing | fopts FO.Rules -> applyRules lup (Info.fetch (tvrInfo v)) xs
hunk ./E/SSimplify.hs 493
-        z <- applyRule v xs'
+        z <- applyRule v xs' inb
hunk ./E/SSimplify.hs 499
-        z <- applyRule v xs'
+        z <- applyRule v xs' inb
hunk ./E/TypeCheck.hs 273
-match :: Monad m => [TVr] -> E -> E -> m [(TVr,E)]
-match vs e1 e2 = liftM Seq.toList $ execWriterT (un e1 e2 () (0::Int)) where
+match :: Monad m =>
+    (Id -> Maybe E)      -- ^ function to look up values in the environment
+    -> [TVr]              -- ^ vars which may be substituted
+    -> E                  -- ^ pattern to match
+    -> E                  -- ^ input expression
+    -> m [(TVr,E)]
+match lup vs e1 e2 = liftM Seq.toList $ execWriterT (un e1 e2 () (0::Int)) where
hunk ./E/TypeCheck.hs 298
+    un a@EVar {} b mm c = fail $ "Expressions do not unify: " ++ show a ++ show b
+    un a (EVar tvr) mm c | Just b <- lup (tvrIdent tvr), not $ isEVar b = un a b mm c