@@ -155,7 +155,7 @@ data Err' t
155155 | WithFnType t
156156 | NoTypeDecl Name
157157 | NotInjective t t t
158− | CantResolve Bool -- ^ True if postponed, False if fatal
158+ | CantResolve Bool -- True if postponed, False if fatal
159159 t
160160 | CantResolveAlts [Name]
161161 | IncompleteTerm t
@@ -936,6 +936,7 @@ vinstances i t = 0
936936-- | Replace the outermost (index 0) de Bruijn variable with the given term
937937instantiate :: TT n -> TT n -> TT n
938938instantiate e = subst 0 where
939+ subst i (P nt x ty) = P nt x (subst i ty)
939940 subst i (V x) | i == x = e
940941 subst i (Bind x b sc) = Bind x (fmap (subst i) b) (subst (i+1) sc)
941942 subst i (App f a) = App (subst i f) (subst i a)
@@ -947,6 +948,7 @@ instantiate e = subst 0 where
947948-- that has been substituted.
948949substV :: TT n -> TT n -> TT n
949950substV x tm = dropV 0 (instantiate x tm) where
951+ subst i (P nt x ty) = P nt x (subst i ty)
950952 dropV i (V x) | x > i = V (x - 1)
951953 | otherwise = V x
952954 dropV i (Bind x b sc) = Bind x (fmap (dropV i) b) (dropV (i+1) sc)
@@ -1040,6 +1042,9 @@ subst n v tm = fst $ subst' 0 tm
10401042 -- substitution happens...)
10411043 subst' i (V x) | i == x = (v, True)
10421044 subst' i (P _ x _) | n == x = (v, True)
1045+ subst' i t@(P nt x ty)
1046+ = let (ty', ut) = subst' i ty in
1047+ if ut then (P nt x ty', True) else (t, False)
10431048 subst' i t@(Bind x b sc) | x /= n
10441049 = let (b', ub) = substB' i b
10451050 (sc', usc) = subst' (i+1) sc in