@@ -35,8 +35,15 @@ match_unify :: Context -> Env -> TT Name -> TT Name -> [Name] -> [Name] ->
3535match_unify ctxt env topx topy dont holes =
3636-- trace ("Matching " ++ show (topx, topy)) $
3737 case runStateT (un [] topx topy) (UI 0 []) of
38− OK (v, UI _ fails) -> return (filter notTrivial v)
39− Error e -> tfail e
38+ OK (v, UI _ []) -> return (filter notTrivial v)
39+ res ->
40+ let topxn = normalise ctxt env topx
41+ topyn = normalise ctxt env topy in
42+ case runStateT (un [] topxn topyn)
43+ (UI 0 []) of
44+ OK (v, UI _ fails) ->
45+ return (filter notTrivial v)
46+ Error e -> tfail e
4047 where
4148 un names (P _ x _) tm
4249 | holeIn env x || x `elem` holes
@@ -44,8 +51,6 @@ match_unify ctxt env topx topy dont holes =
4451 un names tm (P _ y _)
4552 | holeIn env y || y `elem` holes
4653 = do sc 1; checkCycle (y, tm)
47− un names x y
48− | OK True <- convEq' ctxt x y = do sc 1; return []
4954 un bnames (V i) (P _ x _)
5055 | fst (bnames!!i) == x || snd (bnames!!i) == x = do sc 1; return []
5156 un bnames (P _ x _) (V i)
@@ -54,6 +59,15 @@ match_unify ctxt env topx topy dont holes =
5459 = do hf <- un names fx fy
5560 ha <- un names ax ay
5661 combine names hf ha
62+ un names x y
63+ | OK True <- convEq' ctxt x y = do sc 1; return []
64+ | otherwise = do UI s f <- get
65+ let r = recoverable x y
66+ let err = CantUnify r
67+ topx topy (CantUnify r x y (Msg "") [] s) (errEnv env) s
68+ if (not r) then lift $ tfail err
69+ else do put (UI s ((x, y, env, err) : f))
70+ lift $ tfail err
5771
5872
5973 -- TODO: there's an annoying amount of repetition between this and the