@@ -290,7 +290,7 @@ prepare_apply fn imps =
290290 env <- get_env
291291 -- let claims = getArgs ty imps
292292 -- claims <- mkClaims (normalise ctxt env ty) imps []
293− claims <- mkClaims (finalise ty) imps []
293+ claims <- mkClaims (finalise ty) imps [] (map fst env)
294294 ES (p, a) s prev <- get
295295 -- reverse the claims we made so that args go left to right
296296 let n = length (filter not imps)
@@ -301,15 +301,17 @@ prepare_apply fn imps =
301301-- (h : _) -> reorder_claims h
302302 return claims
303303 where
304− mkClaims (Bind n' (Pi t) sc) (i : is) claims =
305− do n <- unique_hole (mkMN n')
304+ mkClaims (Bind n' (Pi t_in) sc) (i : is) claims hs =
305+ do let t = rebind hs t_in
306+ n <- unique_hole (mkMN n')
306307-- when (null claims) (start_unify n)
307308 let sc' = instantiate (P Bound n t) sc
309+-- trace ("CLAIMING " ++ show (n, t) ++ " with " ++ show hs) $
308310 claim n (forget t)
309311 when i (movelast n)
310− mkClaims sc' is (n : claims)
311− mkClaims t [] claims = return (reverse claims)
312− mkClaims _ _ _
312+ mkClaims sc' is (n : claims) hs
313+ mkClaims t [] claims _ = return (reverse claims)
314+ mkClaims _ _ _ _
313315 | Var n <- fn
314316 = do ctxt <- get_context
315317 case lookupTy Nothing n ctxt of
@@ -324,6 +326,13 @@ prepare_apply fn imps =
324326 mkMN n@(UN x) = MN 1000 x
325327 mkMN (NS n xs) = NS (mkMN n) xs
326328
329+ rebind hs (Bind n t sc)
330+ | n `elem` hs = let n' = uniqueName n hs in
331+ Bind n' (fmap (rebind hs) t) (rebind (n':hs) sc)
332+ | otherwise = Bind n (fmap (rebind hs) t) (rebind (n:hs) sc)
333+ rebind hs (App f a) = App (rebind hs f) (rebind hs a)
334+ rebind hs t = t
335+
327336apply :: Raw -> [(Bool, Int)] -> Elab' aux [Name]
328337apply fn imps =
329338 do args <- prepare_apply fn (map fst imps)
@@ -343,7 +352,9 @@ apply fn imps =
343352 unified p
344353 let unify = dropGiven dont hs
345354 put (ES (p { dontunify = dont, unified = (n, unify) }, a) s prev)
355+ ptm <- get_term
346356 end_unify
357+ ptm <- get_term
347358 return (map (updateUnify unify) args)
348359 where updateUnify hs n = case lookup n hs of
349360 Just (P _ t _) -> t
@@ -410,7 +421,7 @@ apply_elab n args =
410421 focus n; elaboration; elabClaims failed r xs
411422
412423 mkMN n@(MN _ _) = n
413− mkMN n@(UN x) = MN 0 x
424+ mkMN n@(UN x) = MN 1000 x
414425 mkMN (NS n ns) = NS (mkMN n) ns
415426
416427simple_app :: Elab' aux () -> Elab' aux () -> Elab' aux ()