@@ -290,7 +290,7 @@ prepare_apply fn imps =
290 env <- get_env
290 env <- get_env
291 -- let claims = getArgs ty imps
291 -- let claims = getArgs ty imps
292 -- claims <- mkClaims (normalise ctxt env ty) imps []
292 -- claims <- mkClaims (normalise ctxt env ty) imps []
293− claims <- mkClaims (finalise ty) imps []
293+ claims <- mkClaims (finalise ty) imps [] (map fst env)
294 ES (p, a) s prev <- get
294 ES (p, a) s prev <- get
295 -- reverse the claims we made so that args go left to right
295 -- reverse the claims we made so that args go left to right
296 let n = length (filter not imps)
296 let n = length (filter not imps)
@@ -301,15 +301,17 @@ prepare_apply fn imps =
301-- (h : _) -> reorder_claims h
301-- (h : _) -> reorder_claims h
302 return claims
302 return claims
304− mkClaims (Bind n' (Pi t) sc) (i : is) claims =
304+ mkClaims (Bind n' (Pi t_in) sc) (i : is) claims hs =
305+ do let t = rebind hs t_in
305− do n <- unique_hole (mkMN n')
306+ n <- unique_hole (mkMN n')
306-- when (null claims) (start_unify n)
307-- when (null claims) (start_unify n)
307 let sc' = instantiate (P Bound n t) sc
308 let sc' = instantiate (P Bound n t) sc
309+-- trace ("CLAIMING " ++ show (n, t) ++ " with " ++ show hs) $
308 claim n (forget t)
310 claim n (forget t)
309 when i (movelast n)
311 when i (movelast n)
310− mkClaims sc' is (n : claims)
312+ mkClaims sc' is (n : claims) hs
311− mkClaims t [] claims = return (reverse claims)
313+ mkClaims t [] claims _ = return (reverse claims)
312− mkClaims _ _ _
314+ mkClaims _ _ _ _
313 | Var n <- fn
315 | Var n <- fn
314 = do ctxt <- get_context
316 = do ctxt <- get_context
315 case lookupTy Nothing n ctxt of
317 case lookupTy Nothing n ctxt of
@@ -324,6 +326,13 @@ prepare_apply fn imps =
324 mkMN n@(UN x) = MN 1000 x
326 mkMN n@(UN x) = MN 1000 x
325 mkMN (NS n xs) = NS (mkMN n) xs
327 mkMN (NS n xs) = NS (mkMN n) xs
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)
327apply :: Raw -> [(Bool, Int)] -> Elab' aux [Name]
336apply :: Raw -> [(Bool, Int)] -> Elab' aux [Name]
328apply fn imps =
337apply fn imps =
329 do args <- prepare_apply fn (map fst imps)
338 do args <- prepare_apply fn (map fst imps)
@@ -343,7 +352,9 @@ apply fn imps =
343 unified p
352 unified p
344 let unify = dropGiven dont hs
353 let unify = dropGiven dont hs
345 put (ES (p { dontunify = dont, unified = (n, unify) }, a) s prev)
354 put (ES (p { dontunify = dont, unified = (n, unify) }, a) s prev)
346 end_unify
356 end_unify
347 return (map (updateUnify unify) args)
358 return (map (updateUnify unify) args)
348 where updateUnify hs n = case lookup n hs of
359 where updateUnify hs n = case lookup n hs of
349 Just (P _ t _) -> t
360 Just (P _ t _) -> t
@@ -410,7 +421,7 @@ apply_elab n args =
410 focus n; elaboration; elabClaims failed r xs
421 focus n; elaboration; elabClaims failed r xs
412 mkMN n@(MN _ _) = n
423 mkMN n@(MN _ _) = n
413− mkMN n@(UN x) = MN 0 x
424+ mkMN n@(UN x) = MN 1000 x
414 mkMN (NS n ns) = NS (mkMN n) ns
425 mkMN (NS n ns) = NS (mkMN n) ns
416simple_app :: Elab' aux () -> Elab' aux () -> Elab' aux ()
427simple_app :: Elab' aux () -> Elab' aux () -> Elab' aux ()