@@ -487,7 +487,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
487 -- dontunify = dontunify ps \\ [x],
487 -- dontunify = dontunify ps \\ [x],
488 -- unified = (uh, uns ++ [(x, val)]),
488 -- unified = (uh, uns ++ [(x, val)]),
489 instances = instances ps \\ [x] })
489 instances = instances ps \\ [x] })
490− let tm' = instantiate val (pToV x sc) in
490+ let tm' = subst x val sc in
491 return tm'
491 return tm'
492 | otherwise = lift $ tfail $ IncompleteTerm val
492 | otherwise = lift $ tfail $ IncompleteTerm val
493solve _ _ h@(Bind x t sc)
493solve _ _ h@(Bind x t sc)
@@ -513,7 +513,7 @@ introTy ty mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
513 (tyv, tyt) <- lift $ check ctxt env ty
513 (tyv, tyt) <- lift $ check ctxt env ty
514-- ns <- lift $ unify ctxt env tyv t'
514-- ns <- lift $ unify ctxt env tyv t'
515 case t' of
515 case t' of
516− Bind y (Pi s) t -> let t' = instantiate (P Bound n s) (pToV y t) in
516+ Bind y (Pi s) t -> let t' = subst y (P Bound n s) t in
517 do ns <- unify' ctxt env s tyv
517 do ns <- unify' ctxt env s tyv
518 ps <- get
518 ps <- get
519 let (uh, uns) = unified ps
519 let (uh, uns) = unified ps
@@ -532,7 +532,7 @@ intro mn ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
532 _ -> hnf ctxt env t
532 _ -> hnf ctxt env t
533 case t' of
533 case t' of
534 Bind y (Pi s) t -> -- trace ("in type " ++ show t') $
534 Bind y (Pi s) t -> -- trace ("in type " ++ show t') $
535− let t' = instantiate (P Bound n s) (pToV y t) in
535+ let t' = subst y (P Bound n s) t in
536 return $ Bind n (Lam s) (Bind x (Hole t') (P Bound x t'))
536 return $ Bind n (Lam s) (Bind x (Hole t') (P Bound x t'))
537 _ -> lift $ tfail $ CantIntroduce t'
537 _ -> lift $ tfail $ CantIntroduce t'
538intro n ctxt env _ = fail "Can't introduce here."
538intro n ctxt env _ = fail "Can't introduce here."
@@ -548,7 +548,7 @@ forall n ty ctxt env _ = fail "Can't pi bind here"
548patvar :: Name -> RunTactic
548patvar :: Name -> RunTactic
549patvar n ctxt env (Bind x (Hole t) sc) =
549patvar n ctxt env (Bind x (Hole t) sc) =
550 do action (\ps -> ps { holes = holes ps \\ [x] })
550 do action (\ps -> ps { holes = holes ps \\ [x] })
551− return $ Bind n (PVar t) (instantiate (P Bound n t) (pToV x sc))
551+ return $ Bind n (PVar t) (subst x (P Bound n t) sc)
552patvar n ctxt env tm = fail $ "Can't add pattern var at " ++ show tm
552patvar n ctxt env tm = fail $ "Can't add pattern var at " ++ show tm
554letbind :: Name -> Raw -> Raw -> RunTactic
554letbind :: Name -> Raw -> Raw -> RunTactic
@@ -662,7 +662,7 @@ patbind n ctxt env (Bind x (Hole t) (P _ x' _)) | x == x' =
662 x@(Bind y (PVTy s) t) -> x
662 x@(Bind y (PVTy s) t) -> x
663 _ -> hnf ctxt env t
663 _ -> hnf ctxt env t
664 case t' of
664 case t' of
665− Bind y (PVTy s) t -> let t' = instantiate (P Bound n s) (pToV y t) in
665+ Bind y (PVTy s) t -> let t' = subst y (P Bound n s) t in
666 return $ Bind n (PVar s) (Bind x (Hole t') (P Bound x t'))
666 return $ Bind n (PVar s) (Bind x (Hole t') (P Bound x t'))
667 _ -> fail "Nothing to pattern bind"
667 _ -> fail "Nothing to pattern bind"
668patbind n ctxt env _ = fail "Can't pattern bind here"
668patbind n ctxt env _ = fail "Can't pattern bind here"
@@ -742,7 +742,7 @@ keepGiven du (u : us) hs = keepGiven du us hs
742updateSolved xs x = -- trace ("Updating " ++ show xs ++ " in " ++ show x) $
742updateSolved xs x = -- trace ("Updating " ++ show xs ++ " in " ++ show x) $
743 updateSolved' xs x
743 updateSolved' xs x
744updateSolved' xs (Bind n (Hole ty) t)
744updateSolved' xs (Bind n (Hole ty) t)
745− | Just v <- lookup n xs = instantiate v (pToV n (updateSolved' xs t))
745+ | Just v <- lookup n xs = psubst n v (updateSolved' xs t)
746updateSolved' xs (Bind n b t)
746updateSolved' xs (Bind n b t)
747 | otherwise = Bind n (fmap (updateSolved' xs) b) (updateSolved' xs t)
747 | otherwise = Bind n (fmap (updateSolved' xs) b) (updateSolved' xs t)
748updateSolved' xs (App f a) = App (updateSolved' xs f) (updateSolved' xs a)
748updateSolved' xs (App f a) = App (updateSolved' xs f) (updateSolved' xs a)
@@ -759,7 +759,7 @@ updateError ns e = e
760solveInProblems x val [] = []
760solveInProblems x val [] = []
761solveInProblems x val ((l, r, env, err) : ps)
761solveInProblems x val ((l, r, env, err) : ps)
762− = ((instantiate val (pToV x l), instantiate val (pToV x r),
762+ = ((psubst x val l, psubst x val r,
763 updateEnv [(x, val)] env, err) : solveInProblems x val ps)
763 updateEnv [(x, val)] env, err) : solveInProblems x val ps)
765updateNotunified ns nu = up nu where
765updateNotunified ns nu = up nu where