@@ -253,7 +253,7 @@ qed = do processTactic' QED
253253undo :: Elab' aux ()
254254undo = processTactic' Undo
255255
256−prepare_apply :: Raw -> [(Bool, Int)] -> Elab' aux [Name]
256+prepare_apply :: Raw -> [Bool] -> Elab' aux [Name]
257257prepare_apply fn imps =
258258 do ty <- get_type fn
259259 ctxt <- get_context
@@ -262,7 +262,7 @@ prepare_apply fn imps =
262262 claims <- mkClaims (normalise ctxt env ty) imps []
263263 ES (p, a) s prev <- get
264264 -- reverse the claims we made so that args go left to right
265− let n = length (filter not (map fst imps))
265+ let n = length (filter not imps)
266266 let (h : hs) = holes p
267267 put (ES (p { holes = h : (reverse (take n hs) ++ drop n hs) }, a) s prev)
268268-- case claims of
@@ -275,7 +275,7 @@ prepare_apply fn imps =
275275-- when (null claims) (start_unify n)
276276 let sc' = instantiate (P Bound n t) sc
277277 claim n (forget t)
278− when (fst i) (movelast n)
278+ when i (movelast n)
279279 mkClaims sc' is (n : claims)
280280 mkClaims t [] claims = return (reverse claims)
281281 mkClaims _ _ _ = fail $ "Wrong number of arguments for " ++ show fn
@@ -289,20 +289,40 @@ prepare_apply fn imps =
289289
290290apply :: Raw -> [(Bool, Int)] -> Elab' aux [Name]
291291apply fn imps =
292− do args <- prepare_apply fn imps
292+ do args <- prepare_apply fn (map fst imps)
293293 fill (raw_apply fn (map Var args))
294294 -- *Don't* solve the arguments we're specifying by hand.
295295 -- (remove from unified list before calling end_unify)
296296 -- HMMM: Actually, if we get it wrong, the typechecker will complain!
297297 -- so do nothing
298298 ptm <- get_term
299− let dontunify = [] -- map fst (filter (not.snd) (zip args imps))
299+ let dontunify = [] -- map fst (filter (not.snd) (zip args (map fst imps)))
300300 ES (p, a) s prev <- get
301301 let (n, hs) = unified p
302302 let unify = (n, filter (\ (n, t) -> not (n `elem` dontunify)) hs)
303303 put (ES (p { unified = unify }, a) s prev)
304304 end_unify
305− return args
305+ return (map (updateUnify hs) args)
306+ where updateUnify hs n = case lookup n hs of
307+ Just (P _ t _) -> t
308+ _ -> n
309+
310+apply2 :: Raw -> [Maybe (Elab' aux ())] -> Elab' aux ()
311+apply2 fn elabs =
312+ do args <- prepare_apply fn (map isJust elabs)
313+ fill (raw_apply fn (map Var args))
314+ elabArgs args elabs
315+ ES (p, a) s prev <- get
316+ let (n, hs) = unified p
317+ end_unify
318+ solve
319+ where elabArgs [] [] = return ()
320+ elabArgs (n:ns) (Just e:es) = do focus n; e
321+ elabArgs ns es
322+ elabArgs (n:ns) (_:es) = elabArgs ns es
323+
324+ isJust (Just _) = False
325+ isJust _ = True
306326
307327apply_elab :: Name -> [Maybe (Int, Elab' aux ())] -> Elab' aux ()
308328apply_elab n args =