@@ -32,7 +32,7 @@ type Injs = [(TT Name, TT Name, TT Name)]
3232type Fails = [(TT Name, TT Name, Env, Err, [FailContext], FailAt)]
3333
3434unrecoverable :: Fails -> Bool
35−unrecoverable = any bad
35+unrecoverable = any bad
3636 where bad (_,_,_, err, _, _) = unrec err
3737
3838 unrec (CantUnify r _ _ _ _ _) = not r
@@ -92,12 +92,12 @@ match_unify ctxt env topx topy inj holes from =
9292 | (P (DCon _ _ _) _ _, _) <- unApply x,
9393 holeIn env f || f `elem` holes
9494 = let n' = uniqueName (sMN 0 "mv") (map fst env) in
95− checkCycle names (f, Bind n' (Lam t) x)
95+ checkCycle names (f, Bind n' (Lam t) x)
9696 un names tm@(App (P _ f (Bind fn (Pi t _) sc)) a) x
9797 | (P (DCon _ _ _) _ _, _) <- unApply x,
9898 holeIn env f || f `elem` holes
9999 = let n' = uniqueName fn (map fst env) in
100− checkCycle names (f, Bind n' (Lam t) x)
100+ checkCycle names (f, Bind n' (Lam t) x)
101101
102102 un names tx@(P _ x _) tm
103103 | tx /= tm && holeIn env x || x `elem` holes
@@ -106,12 +106,12 @@ match_unify ctxt env topx topy inj holes from =
106106 | ty /= tm && holeIn env y || y `elem` holes
107107 = do sc 1; checkCycle names (y, tm)
108108 un bnames (V i) (P _ x _)
109− | length bnames > i,
110− fst (fst (bnames!!i)) == x ||
109+ | length bnames > i,
110+ fst (fst (bnames!!i)) == x ||
111111 snd (fst (bnames!!i)) == x = do sc 1; return []
112112 un bnames (P _ x _) (V i)
113113 | length bnames > i,
114− fst (fst (bnames!!i)) == x ||
114+ fst (fst (bnames!!i)) == x ||
115115 snd (fst (bnames!!i)) == x = do sc 1; return []
116116 un bnames (Bind x bx sx) (Bind y by sy) | notHole bx && notHole by
117117 = do h1 <- uB bnames bx by
@@ -124,7 +124,7 @@ match_unify ctxt env topx topy inj holes from =
124124 un names x y
125125 | OK True <- convEq' ctxt holes x y = do sc 1; return []
126126 | otherwise = do UI s f <- get
127− let r = recoverable (normalise ctxt env x)
127+ let r = recoverable (normalise ctxt env x)
128128 (normalise ctxt env y)
129129 let err = cantUnify from r
130130 topx topy (CantUnify r x y (Msg "") (errEnv env) s) (errEnv env) s
@@ -139,7 +139,7 @@ match_unify ctxt env topx topy inj holes from =
139139 uB bnames (Lam tx) (Lam ty) = un bnames tx ty
140140 uB bnames (Pi tx _) (Pi ty _) = un bnames tx ty
141141 uB bnames x y = do UI s f <- get
142− let r = recoverable (normalise ctxt env (binderTy x))
142+ let r = recoverable (normalise ctxt env (binderTy x))
143143 (normalise ctxt env (binderTy y))
144144 let err = cantUnify from r topx topy
145145 (CantUnify r (binderTy x) (binderTy y) (Msg "") (errEnv env) s)
@@ -152,12 +152,13 @@ match_unify ctxt env topx topy inj holes from =
152152
153153 -- TODO: there's an annoying amount of repetition between this and the
154154 -- main unification function. Consider lifting it out.
155+ -- Issue #1721 on the issue tracker: https://github.com/idris-lang/Idris-dev/issues/1721
155156
156157 sc i = do UI s f <- get
157158 put (UI (s+i) f)
158159
159160 unifyFail x y = do UI s f <- get
160− let r = recoverable (normalise ctxt env x)
161+ let r = recoverable (normalise ctxt env x)
161162 (normalise ctxt env y)
162163 let err = cantUnify from r
163164 topx topy (CantUnify r x y (Msg "") (errEnv env) s) (errEnv env) s
@@ -192,23 +193,23 @@ match_unify ctxt env topx topy inj holes from =
192193 where inst [] tm = tm
193194 inst ((n, _) : ns) tm = inst ns (substV (P Bound n Erased) tm)
194195
195− bind i ns tm
196+ bind i ns tm
196197 | i < 0 = tm
197198 | otherwise = let ((x,y),ty) = ns!!i in
198199 App (Bind y (Lam ty) (bind (i-1) ns tm))
199200 (P Bound x ty)
200−
201+
201202renameBinders env (x, t) = (x, renameBindersTm env t)
202203
203204renameBindersTm :: Env -> TT Name -> TT Name
204205renameBindersTm env tm = uniqueBinders (map fst env) tm
205206 where
206207 uniqueBinders env (Bind n b sc)
207− | n `elem` env
208+ | n `elem` env
208209 = let n' = uniqueName n env in
209210 explicitHole $ Bind n' (fmap (uniqueBinders env) b)
210211 (uniqueBinders (n':env) (rename n n' sc))
211− | otherwise = Bind n (fmap (uniqueBinders (n:env)) b)
212+ | otherwise = Bind n (fmap (uniqueBinders (n:env)) b)
212213 (uniqueBinders (n:env) sc)
213214 uniqueBinders env (App f a) = App (uniqueBinders env f) (uniqueBinders env a)
214215 uniqueBinders env t = t
@@ -218,7 +219,7 @@ renameBindersTm env tm = uniqueBinders (map fst env) tm
218219 rename n n' (App f a) = App (rename n n' f) (rename n n' a)
219220 rename n n' t = t
220221
221− explicitHole (Bind n (Hole ty) sc)
222+ explicitHole (Bind n (Hole ty) sc)
222223 = Bind n (Hole ty) (instantiate (P Bound n ty) sc)
223224 explicitHole t = t
224225
@@ -227,7 +228,7 @@ trimSolutions ns = followSols (dropPairs ns)
227228 dropPairs (n@(x, P _ x' _) : ns)
228229 | x == x' = dropPairs ns
229230 | otherwise
230− = n : dropPairs
231+ = n : dropPairs
231232 (filter (\t -> case t of
232233 (n, P _ n' _) -> not (n == x' && n' == x)
233234 _ -> True) ns)
@@ -253,14 +254,14 @@ hasv (App f a) = hasv f || hasv a
253254hasv (Bind x b sc) = hasv (binderTy b) || hasv sc
254255hasv _ = False
255256
256−unify :: Context -> Env -> TT Name -> TT Name ->
257+unify :: Context -> Env -> TT Name -> TT Name ->
257258 [Name] -> [Name] -> [Name] -> [FailContext] ->
258259 TC ([(Name, TT Name)], Fails)
259260unify ctxt env topx topy inj holes usersupp from =
260−-- traceWhen (hasv topx || hasv topy)
261+-- traceWhen (hasv topx || hasv topy)
261262-- ("Unifying " ++ show topx ++ "\nAND\n" ++ show topy ++ "\n") $
262263 -- don't bother if topx and topy are different at the head
263− case runStateT (un False [] (renameBindersTm env topx)
264+ case runStateT (un False [] (renameBindersTm env topx)
264265 (renameBindersTm env topy)) (UI 0 []) of
265266 OK (v, UI _ []) -> return (map (renameBinders env) (trimSolutions v),
266267 [])
@@ -271,7 +272,7 @@ unify ctxt env topx topy inj holes usersupp from =
271272 case runStateT (un False [] topxn topyn)
272273 (UI 0 []) of
273274 OK (v, UI _ fails) ->
274− return (map (renameBinders env) (trimSolutions v),
275+ return (map (renameBinders env) (trimSolutions v),
275276 reverse fails)
276277-- Error e@(CantUnify False _ _ _ _ _) -> tfail e
277278 Error e -> tfail e
@@ -287,8 +288,8 @@ unify ctxt env topx topy inj holes usersupp from =
287288 injective (App f a) = injective f -- && injective a
288289 injective _ = False
289290
290−-- injectiveVar (P _ (MN _ _) _) = True -- TMP HACK
291− injectiveVar (P _ n _) = n `elem` inj
291+-- injectiveVar (P _ (MN _ _) _) = True -- TMP HACK
292+ injectiveVar (P _ n _) = n `elem` inj
292293 injectiveVar (App f a) = injectiveVar f -- && injective a
293294 injectiveVar _ = False
294295
@@ -364,7 +365,7 @@ unify ctxt env topx topy inj holes usersupp from =
364365 then unifyTmpFail xtm tm
365366 else do sc 1
366367 return x
367− | pureTerm tm, not (injective xtm) && injective tm
368+ | pureTerm tm, not (injective xtm) && injective tm
368369 = do checkCycle bnames (x, tm)
369370 unifyTmpFail xtm tm
370371 un' fn bnames tm ytm@(P _ y _)
@@ -378,16 +379,16 @@ unify ctxt env topx topy inj holes usersupp from =
378379 then unifyTmpFail tm ytm
379380 else do sc 1
380381 return x
381− | pureTerm tm, not (injective ytm) && injective tm
382+ | pureTerm tm, not (injective ytm) && injective tm
382383 = do checkCycle bnames (y, tm)
383384 unifyTmpFail tm ytm
384385 un' fn bnames (V i) (P _ x _)
385386 | length bnames > i,
386− fst ((map fst bnames)!!i) == x ||
387+ fst ((map fst bnames)!!i) == x ||
387388 snd ((map fst bnames)!!i) == x = do sc 1; return []
388389 un' fn bnames (P _ x _) (V i)
389390 | length bnames > i,
390− fst ((map fst bnames)!!i) == x ||
391+ fst ((map fst bnames)!!i) == x ||
391392 snd ((map fst bnames)!!i) == x = do sc 1; return []
392393
393394 un' fn names topx@(Bind n (Hole t) sc) y = unifyTmpFail topx y
@@ -417,17 +418,17 @@ unify ctxt env topx topy inj holes usersupp from =
417418 un' fn bnames (App f x) (Bind n (Pi t k) y)
418419 | noOccurrence n y && injectiveApp f
419420 = do ux <- un' False bnames x y
420− uf <- un' False bnames f (Bind (sMN 0 "uv") (Lam (TType (UVar 0)))
421+ uf <- un' False bnames f (Bind (sMN 0 "uv") (Lam (TType (UVar 0)))
421422 (Bind n (Pi t k) (V 1)))
422423 combine bnames ux uf
423−
424+
424425 un' fn bnames (Bind n (Pi t k) y) (App f x)
425426 | noOccurrence n y && injectiveApp f
426427 = do ux <- un' False bnames y x
427− uf <- un' False bnames (Bind (sMN 0 "uv") (Lam (TType (UVar 0)))
428+ uf <- un' False bnames (Bind (sMN 0 "uv") (Lam (TType (UVar 0)))
428429 (Bind n (Pi t k) (V 1))) f
429430 combine bnames ux uf
430−
431+
431432 un' fn bnames (Bind x bx sx) (Bind y by sy)
432433 | sameBinder bx by
433434 = do h1 <- uB bnames bx by
@@ -438,9 +439,9 @@ unify ctxt env topx topy inj holes usersupp from =
438439 sameBinder _ _ = False
439440 un' fn bnames x y
440441 | OK True <- convEq' ctxt holes x y = do sc 1; return []
441− | isUniverse x && isUniverse y = do sc 1; return []
442+ | isUniverse x && isUniverse y = do sc 1; return []
442443 | otherwise = do UI s f <- get
443− let r = recoverable (normalise ctxt env x)
444+ let r = recoverable (normalise ctxt env x)
444445 (normalise ctxt env y)
445446 let err = cantUnify from r
446447 topx topy (CantUnify r x y (Msg "") (errEnv env) s) (errEnv env) s
@@ -519,7 +520,7 @@ unify ctxt env topx topy inj holes usersupp from =
519520 _ -> False
520521
521522 metavar t = case t of
522− P _ x _ -> (x `notElem` usersupp &&
523+ P _ x _ -> (x `notElem` usersupp &&
523524 (x `elem` holes || holeIn env x))
524525 || globmetavar t
525526 _ -> False
@@ -566,7 +567,7 @@ unify ctxt env topx topy inj holes usersupp from =
566567 uB bnames (Hole tx) (Hole ty) = un' False bnames tx ty
567568 uB bnames (PVar tx) (PVar ty) = un' False bnames tx ty
568569 uB bnames x y = do UI s f <- get
569− let r = recoverable (normalise ctxt env (binderTy x))
570+ let r = recoverable (normalise ctxt env (binderTy x))
570571 (normalise ctxt env (binderTy y))
571572 let err = cantUnify from r topx topy
572573 (CantUnify r (binderTy x) (binderTy y) (Msg "") (errEnv env) s)
@@ -590,9 +591,9 @@ unify ctxt env topx topy inj holes usersupp from =
590591 else return [(x, bind v ns tm)]
591592 where inst [] tm = tm
592593 inst (((n, _), _) : ns) tm = inst ns (substV (P Bound n Erased) tm)
593− checkScope ns (x, tm) = lift $ tfail (Msg "HOLE ERROR")
594+ checkScope ns (x, tm) = lift $ tfail (Msg "HOLE ERROR")
594595
595− bind i ns tm
596+ bind i ns tm
596597 | i < 0 = tm
597598 | otherwise = let ((x,y),ty) = ns!!i in
598599 App (Bind y (Lam ty) (bind (i-1) ns tm))
@@ -639,7 +640,9 @@ envPos x i ((y, _) : ys) | x == y = i
639640-- FIXME: Depending on how overloading gets used, this may cause problems. Better
640641-- rethink overloading properly...
641642-- ASSUMPTION: inputs are in normal form
642−
643+--
644+-- Issue #1722 on the issue tracker https://github.com/idris-lang/Idris-dev/issues/1722
645+--
643646recoverable t@(App _ _) _
644647 | (P _ (UN l) _, _) <- unApply t, l == txt "Lazy'" = False
645648recoverable _ t@(App _ _)
@@ -658,7 +661,7 @@ recoverable (App f a) p@(Constant _) = recoverable f p
658661recoverable p@(P _ n _) (App f a) = recoverable p f
659662recoverable (App f a) p@(P _ _ _) = recoverable f p
660663recoverable (App f a) (App f' a')
661− | f == f' = recoverable a a'
664+ | f == f' = recoverable a a'
662665recoverable (App f a) (App f' a')
663666 = recoverable f f' -- && recoverable a a'
664667recoverable f (Bind _ (Pi _ _) sc)
@@ -685,4 +688,3 @@ patIn env n = case lookup n env of
685688 Just (PVar _) -> True
686689 Just (PVTy _) -> True
687690 _ -> False
688−