@@ -25,12 +25,15 @@ data UInfo = UI Int Injs Fails
25unify :: Context -> Env -> TT Name -> TT Name -> TC ([(Name, TT Name)],
25unify :: Context -> Env -> TT Name -> TT Name -> TC ([(Name, TT Name)],
26 Injs, Fails)
26 Injs, Fails)
27unify ctxt env topx topy
27unify ctxt env topx topy
28− = case runStateT
28+ = -- case runStateT (un' False [] topx topy) (UI 0 [] []) of
29+ -- OK (v, UI _ inj []) -> return (filter notTrivial v, inj, [])
30+ let topxn = normalise ctxt env topx
29− (un' False [] (normalise ctxt env topx) (normalise ctxt env topy))
31+ topyn = normalise ctxt env topy in
32+ case runStateT (un' False [] topxn topyn)
30− (UI 0 [] []) of
33+ (UI 0 [] []) of
31− OK (v, UI _ inj fails) -> return (filter notTrivial v, inj, reverse fails)
34+ OK (v, UI _ inj fails) -> return (filter notTrivial v, inj, reverse fails)
32−-- OK (_, UI s _ ((_,_,f):fs)) -> tfail $ CantUnify topx topy f s
35+-- OK (_, UI s _ ((_,_,f):fs)) -> tfail $ CantUnify topx topy f s
33− Error e -> tfail e
36+ Error e -> tfail e
35 notTrivial (x, P _ x' _) = x /= x'
38 notTrivial (x, P _ x' _) = x /= x'
36 notTrivial _ = True
39 notTrivial _ = True
@@ -76,18 +79,19 @@ unify ctxt env topx topy
76 un' fn bnames (App fx ax) (App fy ay)
79 un' fn bnames (App fx ax) (App fy ay)
77 = do uplus -- do the second one if the first adds any errors
80 = do uplus -- do the second one if the first adds any errors
78 (do hf <- un' True bnames fx fy
81 (do hf <- un' True bnames fx fy
79− let ax' = normalise ctxt env (substNames hf ax)
82+ let ax' = hnormalise hf ctxt env (substNames hf ax)
80− let ay' = normalise ctxt env (substNames hf ay)
83+ let ay' = hnormalise hf ctxt env (substNames hf ay)
81 ha <- un' False bnames ax' ay'
84 ha <- un' False bnames ax' ay'
83 combine bnames hf ha)
86 combine bnames hf ha)
84 (do ha <- un' False bnames ax ay
87 (do ha <- un' False bnames ax ay
85− let fx' = normalise ctxt env (substNames ha fx)
88+ let fx' = hnormalise ha ctxt env (substNames ha fx)
86− let fy' = normalise ctxt env (substNames ha fy)
89+ let fy' = hnormalise ha ctxt env (substNames ha fy)
87 hf <- un' False bnames fx' fy'
90 hf <- un' False bnames fx' fy'
89 combine bnames hf ha)
92 combine bnames hf ha)
90−
93+ where hnormalise [] _ _ t = t
94+ hnormalise ns ctxt env t = normalise ctxt env t
91 un' fn bnames x (Bind n (Lam t) (App y (P Bound n' _)))
95 un' fn bnames x (Bind n (Lam t) (App y (P Bound n' _)))
92 | n == n' = un' False bnames x y
96 | n == n' = un' False bnames x y
93 un' fn bnames (Bind n (Lam t) (App x (P Bound n' _))) y
97 un' fn bnames (Bind n (Lam t) (App x (P Bound n' _))) y