@@ -807,6 +807,11 @@ instance Eq NameType where
807 TCon _ a == TCon _ b = (a == b) -- ignore tag
807 TCon _ a == TCon _ b = (a == b) -- ignore tag
808 _ == _ = False
808 _ == _ = False
810+data AppStatus n = Complete
813+ deriving (Eq, Ord, Functor, Data, Typeable, Show)
810-- | Terms in the core language. The type parameter is the type of
815-- | Terms in the core language. The type parameter is the type of
811-- identifiers used for bindings and explicit named references;
816-- identifiers used for bindings and explicit named references;
812-- usually we use @TT 'Name'@.
817-- usually we use @TT 'Name'@.
@@ -815,7 +820,7 @@ data TT n = P NameType n (TT n) -- ^ named references with type
815 -- Pure Type Systems Formalized)
820 -- Pure Type Systems Formalized)
816 | V !Int -- ^ a resolved de Bruijn-indexed variable
821 | V !Int -- ^ a resolved de Bruijn-indexed variable
817 | Bind n !(Binder (TT n)) (TT n) -- ^ a binding
822 | Bind n !(Binder (TT n)) (TT n) -- ^ a binding
818− | App !(TT n) (TT n) -- ^ function, function type, arg
823+ | App (AppStatus n) !(TT n) (TT n) -- ^ function, function type, arg
819 | Constant Const -- ^ constant
824 | Constant Const -- ^ constant
820 | Proj (TT n) !Int -- ^ argument projection; runtime only
825 | Proj (TT n) !Int -- ^ argument projection; runtime only
821 -- (-1) is a special case for 'subtract one from BI'
826 -- (-1) is a special case for 'subtract one from BI'
@@ -851,7 +856,7 @@ instance TermSize (TT Name) where
851 termsize n (Bind n' b sc)
856 termsize n (Bind n' b sc)
852 = let rn = if n == n' then sMN 0 "noname" else n in
857 = let rn = if n == n' then sMN 0 "noname" else n in
853 termsize rn sc
858 termsize rn sc
854− termsize n (App f a) = termsize n f + termsize n a
859+ termsize n (App _ f a) = termsize n f + termsize n a
855 termsize n (Proj t i) = termsize n t
860 termsize n (Proj t i) = termsize n t
856 termsize n _ = 1
861 termsize n _ = 1
@@ -859,7 +864,7 @@ instance Sized a => Sized (TT a) where
859 size (P name n trm) = 1 + size name + size n + size trm
864 size (P name n trm) = 1 + size name + size n + size trm
860 size (V v) = 1
865 size (V v) = 1
861 size (Bind nm binder bdy) = 1 + size nm + size binder + size bdy
866 size (Bind nm binder bdy) = 1 + size nm + size binder + size bdy
862− size (App l r) = 1 + size l + size r
867+ size (App _ l r) = 1 + size l + size r
863 size (Constant c) = size c
868 size (Constant c) = size c
864 size Erased = 1
869 size Erased = 1
865 size (TType u) = 1 + size u
870 size (TType u) = 1 + size u
@@ -880,8 +885,8 @@ instance Eq n => Eq (TT n) where
880 (==) (P xt x _) (P yt y _) = x == y
885 (==) (P xt x _) (P yt y _) = x == y
881 (==) (V x) (V y) = x == y
886 (==) (V x) (V y) = x == y
882 (==) (Bind _ xb xs) (Bind _ yb ys) = xs == ys && xb == yb
887 (==) (Bind _ xb xs) (Bind _ yb ys) = xs == ys && xb == yb
883− (==) (App fx ax) (App fy ay) = ax == ay && fx == fy
888+ (==) (App _ fx ax) (App _ fy ay) = ax == ay && fx == fy
884− (==) (TType _) (TType _) = True -- deal with constraints later
889+ (==) (TType _) (TType _) = True -- deal with constraints later
885 (==) (Constant x) (Constant y) = x == y
890 (==) (Constant x) (Constant y) = x == y
886 (==) (Proj x i) (Proj y j) = x == y && i == j
891 (==) (Proj x i) (Proj y j) = x == y && i == j
887 (==) Erased _ = True
892 (==) Erased _ = True
@@ -897,15 +902,15 @@ isInjective :: TT n -> Bool
897isInjective (P (DCon _ _ _) _ _) = True
902isInjective (P (DCon _ _ _) _ _) = True
898isInjective (P (TCon _ _) _ _) = True
903isInjective (P (TCon _ _) _ _) = True
899isInjective (Constant _) = True
904isInjective (Constant _) = True
900−isInjective (TType x) = True
905+isInjective (TType x) = True
901isInjective (Bind _ (Pi _ _ _) sc) = True
906isInjective (Bind _ (Pi _ _ _) sc) = True
902−isInjective (App f a) = isInjective f
907+isInjective (App _ f a) = isInjective f
903isInjective _ = False
908isInjective _ = False
905-- | Count the number of instances of a de Bruijn index in a term
910-- | Count the number of instances of a de Bruijn index in a term
906vinstances :: Int -> TT n -> Int
911vinstances :: Int -> TT n -> Int
907vinstances i (V x) | i == x = 1
912vinstances i (V x) | i == x = 1
908−vinstances i (App f a) = vinstances i f + vinstances i a
913+vinstances i (App _ f a) = vinstances i f + vinstances i a
909vinstances i (Bind x b sc) = instancesB b + vinstances (i + 1) sc
914vinstances i (Bind x b sc) = instancesB b + vinstances (i + 1) sc
910 where instancesB (Let t v) = vinstances i v
915 where instancesB (Let t v) = vinstances i v
911 instancesB _ = 0
916 instancesB _ = 0
@@ -917,7 +922,7 @@ instantiate e = subst 0 where
917 subst i (P nt x ty) = P nt x (subst i ty)
922 subst i (P nt x ty) = P nt x (subst i ty)
918 subst i (V x) | i == x = e
923 subst i (V x) | i == x = e
919 subst i (Bind x b sc) = Bind x (fmap (subst i) b) (subst (i+1) sc)
924 subst i (Bind x b sc) = Bind x (fmap (subst i) b) (subst (i+1) sc)
920− subst i (App f a) = App (subst i f) (subst i a)
925+ subst i (App s f a) = App s (subst i f) (subst i a)
921 subst i (Proj x idx) = Proj (subst i x) idx
926 subst i (Proj x idx) = Proj (subst i x) idx
922 subst i t = t
927 subst i t = t
@@ -930,7 +935,7 @@ substV x tm = dropV 0 (instantiate x tm) where
930 dropV i (V x) | x > i = V (x - 1)
935 dropV i (V x) | x > i = V (x - 1)
931 | otherwise = V x
936 | otherwise = V x
932 dropV i (Bind x b sc) = Bind x (fmap (dropV i) b) (dropV (i+1) sc)
937 dropV i (Bind x b sc) = Bind x (fmap (dropV i) b) (dropV (i+1) sc)
933− dropV i (App f a) = App (dropV i f) (dropV i a)
938+ dropV i (App s f a) = App s (dropV i f) (dropV i a)
934 dropV i (Proj x idx) = Proj (dropV i x) idx
939 dropV i (Proj x idx) = Proj (dropV i x) idx
935 dropV i t = t
940 dropV i t = t
@@ -941,7 +946,7 @@ explicitNames (Bind x b sc) = let b' = fmap explicitNames b in
941 Bind x b'
946 Bind x b'
942 (explicitNames (instantiate
947 (explicitNames (instantiate
943 (P Bound x (binderTy b')) sc))
948 (P Bound x (binderTy b')) sc))
944−explicitNames (App f a) = App (explicitNames f) (explicitNames a)
949+explicitNames (App s f a) = App s (explicitNames f) (explicitNames a)
945explicitNames (Proj x idx) = Proj (explicitNames x) idx
950explicitNames (Proj x idx) = Proj (explicitNames x) idx
946explicitNames t = t
951explicitNames t = t
@@ -955,7 +960,7 @@ pToV' n i (Bind x b sc)
955-- resolve names from the *outer* scope which may happen to have the same id.
960-- resolve names from the *outer* scope which may happen to have the same id.
956 | n == x = Bind x (fmap (pToV' n i) b) sc
961 | n == x = Bind x (fmap (pToV' n i) b) sc
957 | otherwise = Bind x (fmap (pToV' n i) b) (pToV' n (i+1) sc)
962 | otherwise = Bind x (fmap (pToV' n i) b) (pToV' n (i+1) sc)
958−pToV' n i (App f a) = App (pToV' n i f) (pToV' n i a)
963+pToV' n i (App s f a) = App s (pToV' n i f) (pToV' n i a)
959pToV' n i (Proj t idx) = Proj (pToV' n i t) idx
964pToV' n i (Proj t idx) = Proj (pToV' n i t) idx
960pToV' n i t = t
965pToV' n i t = t
@@ -966,7 +971,7 @@ addBinder t = ab 0 t
966 ab top (V i) | i >= top = V (i + 1)
971 ab top (V i) | i >= top = V (i + 1)
967 | otherwise = V i
972 | otherwise = V i
968 ab top (Bind x b sc) = Bind x (fmap (ab top) b) (ab (top + 1) sc)
973 ab top (Bind x b sc) = Bind x (fmap (ab top) b) (ab (top + 1) sc)
969− ab top (App f a) = App (ab top f) (ab top a)
974+ ab top (App s f a) = App s (ab top f) (ab top a)
970 ab top (Proj t idx) = Proj (ab top t) idx
975 ab top (Proj t idx) = Proj (ab top t) idx
971 ab top t = t
976 ab top t = t
@@ -985,14 +990,14 @@ vToP = vToP' [] where
985 P Bound n (binderTy b)
990 P Bound n (binderTy b)
986 vToP' env (Bind n b sc) = let b' = fmap (vToP' env) b in
991 vToP' env (Bind n b sc) = let b' = fmap (vToP' env) b in
987 Bind n b' (vToP' ((n, b'):env) sc)
992 Bind n b' (vToP' ((n, b'):env) sc)
988− vToP' env (App f a) = App (vToP' env f) (vToP' env a)
993+ vToP' env (App s f a) = App s (vToP' env f) (vToP' env a)
989 vToP' env t = t
994 vToP' env t = t
991-- | Replace every non-free reference to the name of a binding in
996-- | Replace every non-free reference to the name of a binding in
992-- the given term with a de Bruijn index.
997-- the given term with a de Bruijn index.
993finalise :: Eq n => TT n -> TT n
998finalise :: Eq n => TT n -> TT n
994finalise (Bind x b sc) = Bind x (fmap finalise b) (pToV x (finalise sc))
999finalise (Bind x b sc) = Bind x (fmap finalise b) (pToV x (finalise sc))
995−finalise (App f a) = App (finalise f) (finalise a)
1000+finalise (App s f a) = App s (finalise f) (finalise a)
996finalise t = t
1001finalise t = t
998-- Once we've finished checking everything about a term we no longer need
1003-- Once we've finished checking everything about a term we no longer need
@@ -1000,7 +1005,7 @@ finalise t = t
1001pEraseType :: TT n -> TT n
1006pEraseType :: TT n -> TT n
1002pEraseType (P nt t _) = P nt t Erased
1007pEraseType (P nt t _) = P nt t Erased
1003−pEraseType (App f a) = App (pEraseType f) (pEraseType a)
1008+pEraseType (App s f a) = App s (pEraseType f) (pEraseType a)
1004pEraseType (Bind n b sc) = Bind n (fmap pEraseType b) (pEraseType sc)
1009pEraseType (Bind n b sc) = Bind n (fmap pEraseType b) (pEraseType sc)
1005pEraseType t = t
1010pEraseType t = t
@@ -1027,9 +1032,9 @@ subst n v tm = fst $ subst' 0 tm
1027 = let (b', ub) = substB' i b
1032 = let (b', ub) = substB' i b
1028 (sc', usc) = subst' (i+1) sc in
1033 (sc', usc) = subst' (i+1) sc in
1029 if ub || usc then (Bind x b' sc', True) else (t, False)
1034 if ub || usc then (Bind x b' sc', True) else (t, False)
1030− subst' i t@(App f a) = let (f', uf) = subst' i f
1035+ subst' i t@(App s f a) = let (f', uf) = subst' i f
1031− (a', ua) = subst' i a in
1036+ (a', ua) = subst' i a in
1032− if uf || ua then (App f' a', True) else (t, False)
1037+ if uf || ua then (App s f' a', True) else (t, False)
1033 subst' i t@(Proj x idx) = let (x', u) = subst' i x in
1038 subst' i t@(Proj x idx) = let (x', u) = subst' i x in
1034 if u then (Proj x' idx, u) else (t, False)
1039 if u then (Proj x' idx, u) else (t, False)
1035 subst' i t = (t, False)
1040 subst' i t = (t, False)
@@ -1054,7 +1059,7 @@ psubst n v tm = s' 0 tm where
1054 s' i (P _ x _) | n == x = v
1059 s' i (P _ x _) | n == x = v
1055 s' i (Bind x b sc) | n == x = Bind x (fmap (s' i) b) sc
1060 s' i (Bind x b sc) | n == x = Bind x (fmap (s' i) b) sc
1056 | otherwise = Bind x (fmap (s' i) b) (s' (i+1) sc)
1061 | otherwise = Bind x (fmap (s' i) b) (s' (i+1) sc)
1057− s' i (App f a) = App (s' i f) (s' i a)
1062+ s' i (App st f a) = App st (s' i f) (s' i a)
1058 s' i (Proj t idx) = Proj (s' i t) idx
1063 s' i (Proj t idx) = Proj (s' i t) idx
1059 s' i t = t
1064 s' i t = t
@@ -1072,7 +1077,7 @@ substTerm :: Eq n => TT n {-^ Old term -} ->
1073substTerm old new = st where
1078substTerm old new = st where
1074 st t | t == old = new
1079 st t | t == old = new
1075− st (App f a) = App (st f) (st a)
1080+ st (App s f a) = App s (st f) (st a)
1076 st (Bind x b sc) = Bind x (fmap st b) (st sc)
1081 st (Bind x b sc) = Bind x (fmap st b) (st sc)
1077 st t = t
1082 st t = t
@@ -1086,7 +1091,7 @@ occurrences n t = execState (no' 0 t) 0
1086 where noB' i (Let t v) = do no' i t; no' i v
1091 where noB' i (Let t v) = do no' i t; no' i v
1087 noB' i (Guess t v) = do no' i t; no' i v
1092 noB' i (Guess t v) = do no' i t; no' i v
1088 noB' i b = no' i (binderTy b)
1093 noB' i b = no' i (binderTy b)
1089− no' i (App f a) = do no' i f; no' i a
1094+ no' i (App _ f a) = do no' i f; no' i a
1090 no' i (Proj x _) = no' i x
1095 no' i (Proj x _) = no' i x
1091 no' i _ = return ()
1096 no' i _ = return ()
@@ -1100,7 +1105,7 @@ noOccurrence n t = no' 0 t
1100 where noB' i (Let t v) = no' i t && no' i v
1105 where noB' i (Let t v) = no' i t && no' i v
1101 noB' i (Guess t v) = no' i t && no' i v
1106 noB' i (Guess t v) = no' i t && no' i v
1102 noB' i b = no' i (binderTy b)
1107 noB' i b = no' i (binderTy b)
1103− no' i (App f a) = no' i f && no' i a
1108+ no' i (App _ f a) = no' i f && no' i a
1104 no' i (Proj x _) = no' i x
1109 no' i (Proj x _) = no' i x
1105 no' i _ = True
1110 no' i _ = True
@@ -1112,7 +1117,7 @@ freeNames t = nub $ freeNames' t
1112 freeNames' (Bind n (Let t v) sc) = freeNames' v ++ (freeNames' sc \\ [n])
1117 freeNames' (Bind n (Let t v) sc) = freeNames' v ++ (freeNames' sc \\ [n])
1113 ++ freeNames' t
1118 ++ freeNames' t
1114 freeNames' (Bind n b sc) = freeNames' (binderTy b) ++ (freeNames' sc \\ [n])
1119 freeNames' (Bind n b sc) = freeNames' (binderTy b) ++ (freeNames' sc \\ [n])
1115− freeNames' (App f a) = freeNames' f ++ freeNames' a
1120+ freeNames' (App _ f a) = freeNames' f ++ freeNames' a
1116 freeNames' (Proj x i) = freeNames' x
1121 freeNames' (Proj x i) = freeNames' x
1117 freeNames' _ = []
1122 freeNames' _ = []
@@ -1124,14 +1129,14 @@ arity _ = 0
1124-- | Deconstruct an application; returns the function and a list of arguments
1129-- | Deconstruct an application; returns the function and a list of arguments
1125unApply :: TT n -> (TT n, [TT n])
1130unApply :: TT n -> (TT n, [TT n])
1126unApply t = ua [] t where
1131unApply t = ua [] t where
1127− ua args (App f a) = ua (a:args) f
1132+ ua args (App _ f a) = ua (a:args) f
1128 ua args t = (t, args)
1133 ua args t = (t, args)
1130-- | Returns a term representing the application of the first argument
1135-- | Returns a term representing the application of the first argument
1131-- (a function) to every element of the second argument.
1136-- (a function) to every element of the second argument.
1132mkApp :: TT n -> [TT n] -> TT n
1137mkApp :: TT n -> [TT n] -> TT n
1133mkApp f [] = f
1138mkApp f [] = f
1134−mkApp f (a:as) = mkApp (App f a) as
1139+mkApp f (a:as) = mkApp (App MaybeHoles f a) as
1136unList :: Term -> Maybe [Term]
1141unList :: Term -> Maybe [Term]
1137unList tm = case unApply tm of
1142unList tm = case unApply tm of
@@ -1172,7 +1177,7 @@ safeForgetEnv env (Bind n b sc)
1172 (safeForgetEnv env v)
1177 (safeForgetEnv env v)
1173 safeForgetEnvB env b = do ty' <- safeForgetEnv env (binderTy b)
1178 safeForgetEnvB env b = do ty' <- safeForgetEnv env (binderTy b)
1174 Just $ fmap (\_ -> ty') b
1179 Just $ fmap (\_ -> ty') b
1175−safeForgetEnv env (App f a) = liftM2 RApp (safeForgetEnv env f) (safeForgetEnv env a)
1180+safeForgetEnv env (App _ f a) = liftM2 RApp (safeForgetEnv env f) (safeForgetEnv env a)
1176safeForgetEnv env (Constant c) = Just $ RConstant c
1181safeForgetEnv env (Constant c) = Just $ RConstant c
1177safeForgetEnv env (TType i) = Just RType
1182safeForgetEnv env (TType i) = Just RType
1178safeForgetEnv env (UType u) = Just $ RUType u
1183safeForgetEnv env (UType u) = Just $ RUType u
@@ -1225,7 +1230,7 @@ uniqueBinders ns = ubSet (fromList ns) where
1225 = let n' = uniqueNameSet n ns
1230 = let n' = uniqueNameSet n ns
1226 ns' = insert n' ns in
1231 ns' = insert n' ns in
1227 Bind n' (fmap (ubSet ns') b) (ubSet ns' sc)
1232 Bind n' (fmap (ubSet ns') b) (ubSet ns' sc)
1228− ubSet ns (App f a) = App (ubSet ns f) (ubSet ns a)
1233+ ubSet ns (App s f a) = App s (ubSet ns f) (ubSet ns a)
1229 ubSet ns t = t
1234 ubSet ns t = t
@@ -1318,7 +1323,7 @@ prettyEnv env t = prettyEnv' env t False
1318 bracket p 2 $ prettySb env n b debug <> prettySe 10 ((n, b):env) sc debug
1323 bracket p 2 $ prettySb env n b debug <> prettySe 10 ((n, b):env) sc debug
1319 prettySe p env (Bind n b sc) debug =
1324 prettySe p env (Bind n b sc) debug =
1320 bracket p 2 $ prettySb env n b debug <> prettySe 10 ((n, b):env) sc debug
1325 bracket p 2 $ prettySb env n b debug <> prettySe 10 ((n, b):env) sc debug
1321− prettySe p env (App f a) debug =
1326+ prettySe p env (App _ f a) debug =
1322 bracket p 1 $ prettySe 1 env f debug <+> prettySe 0 env a debug
1327 bracket p 1 $ prettySe 1 env f debug <+> prettySe 0 env a debug
1323 prettySe p env (Proj x i) debug =
1328 prettySe p env (Proj x i) debug =
1324 prettySe 1 env x debug <+> text ("!" ++ show i)
1329 prettySe 1 env x debug <+> text ("!" ++ show i)
@@ -1362,7 +1367,7 @@ showEnv' env t dbg = se 10 env t where
1362 where arrow (TType _) = " -> "
1367 where arrow (TType _) = " -> "
1363 arrow u = " [" ++ show u ++ "] -> "
1368 arrow u = " [" ++ show u ++ "] -> "
1364 se p env (Bind n b sc) = bracket p 2 $ sb env n b ++ se 10 ((n,b):env) sc
1369 se p env (Bind n b sc) = bracket p 2 $ sb env n b ++ se 10 ((n,b):env) sc
1365− se p env (App f a) = bracket p 1 $ se 1 env f ++ " " ++ se 0 env a
1370+ se p env (App _ f a) = bracket p 1 $ se 1 env f ++ " " ++ se 0 env a
1366 se p env (Proj x i) = se 1 env x ++ "!" ++ show i
1371 se p env (Proj x i) = se 1 env x ++ "!" ++ show i
1367 se p env (Constant c) = show c
1372 se p env (Constant c) = show c
1368 se p env Erased = "[__]"
1373 se p env Erased = "[__]"
@@ -1387,9 +1392,9 @@ showEnv' env t dbg = se 10 env t where
1387 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
1392 bracket outer inner str | inner > outer = "(" ++ str ++ ")"
1388 | otherwise = str
1393 | otherwise = str
1390−-- | Check whether a term has any holes in it - impure if so
1395+-- | Check whether a term has any hole bindings in it - impure if so
1391pureTerm :: TT Name -> Bool
1396pureTerm :: TT Name -> Bool
1392−pureTerm (App f a) = pureTerm f && pureTerm a
1397+pureTerm (App _ f a) = pureTerm f && pureTerm a
1393pureTerm (Bind n b sc) = notClassName n && pureBinder b && pureTerm sc where
1398pureTerm (Bind n b sc) = notClassName n && pureBinder b && pureTerm sc where
1394 pureBinder (Hole _) = False
1399 pureBinder (Hole _) = False
1395 pureBinder (Guess _ _) = False
1400 pureBinder (Guess _ _) = False
@@ -1405,7 +1410,7 @@ pureTerm _ = True
1405weakenTm :: Int -> TT n -> TT n
1410weakenTm :: Int -> TT n -> TT n
1406weakenTm i t = wk i 0 t
1411weakenTm i t = wk i 0 t
1407 where wk i min (V x) | x >= min = V (i + x)
1412 where wk i min (V x) | x >= min = V (i + x)
1408− wk i m (App f a) = App (wk i m f) (wk i m a)
1413+ wk i m (App s f a) = App s (wk i m f) (wk i m a)
1409 wk i m (Bind x b sc) = Bind x (wkb i m b) (wk i (m + 1) sc)
1414 wk i m (Bind x b sc) = Bind x (wkb i m b) (wk i (m + 1) sc)
1410 wk i m t = t
1415 wk i m t = t
1411 wkb i m t = fmap (wk i m) t
1416 wkb i m t = fmap (wk i m) t
@@ -1430,7 +1435,7 @@ weakenTmEnv i = map (\ (n, b) -> (n, fmap (weakenTm i) b))
1430orderPats :: Term -> Term
1435orderPats :: Term -> Term
1431orderPats tm = op [] tm
1436orderPats tm = op [] tm
1433− op [] (App f a) = App f (op [] a) -- for Infer terms
1438+ op [] (App s f a) = App s f (op [] a) -- for Infer terms
1435 op ps (Bind n (PVar t) sc) = op ((n, PVar t) : ps) sc
1440 op ps (Bind n (PVar t) sc) = op ((n, PVar t) : ps) sc
1436 op ps (Bind n (Hole t) sc) = op ((n, Hole t) : ps) sc
1441 op ps (Bind n (Hole t) sc) = op ((n, Hole t) : ps) sc
@@ -1455,7 +1460,7 @@ refsIn (Bind n b t) = nub $ nb b ++ refsIn t
1455 where nb (Let t v) = nub (refsIn t) ++ nub (refsIn v)
1460 where nb (Let t v) = nub (refsIn t) ++ nub (refsIn v)
1456 nb (Guess t v) = nub (refsIn t) ++ nub (refsIn v)
1461 nb (Guess t v) = nub (refsIn t) ++ nub (refsIn v)
1457 nb t = refsIn (binderTy t)
1462 nb t = refsIn (binderTy t)
1458−refsIn (App f a) = nub (refsIn f ++ refsIn a)
1463+refsIn (App s f a) = nub (refsIn f ++ refsIn a)
1459refsIn _ = []
1464refsIn _ = []
1461-- Make sure all the pattern bindings are as far out as possible
1466-- Make sure all the pattern bindings are as far out as possible
@@ -1492,9 +1497,9 @@ liftPats tm = let (tm', ps) = runState (getPats tm) [] in
1492 return (Bind n (Hole t') sc')
1497 return (Bind n (Hole t') sc')
1495− getPats (App f a) = do f' <- getPats f
1500+ getPats (App s f a) = do f' <- getPats f
1496− a' <- getPats a
1501+ a' <- getPats a
1497− return (App f' a')
1502+ return (App s f' a')
1498 getPats t = return t
1503 getPats t = return t
1500allTTNames :: Eq n => TT n -> [n]
1505allTTNames :: Eq n => TT n -> [n]
@@ -1504,7 +1509,7 @@ allTTNames = nub . allNamesIn
1504 where nb (Let t v) = allNamesIn t ++ allNamesIn v
1509 where nb (Let t v) = allNamesIn t ++ allNamesIn v
1505 nb (Guess t v) = allNamesIn t ++ allNamesIn v
1510 nb (Guess t v) = allNamesIn t ++ allNamesIn v
1506 nb t = allNamesIn (binderTy t)
1511 nb t = allNamesIn (binderTy t)
1507− allNamesIn (App f a) = allNamesIn f ++ allNamesIn a
1512+ allNamesIn (App _ f a) = allNamesIn f ++ allNamesIn a
1508 allNamesIn _ = []
1513 allNamesIn _ = []
@@ -1527,7 +1532,7 @@ pprintTT bound tm = pp startPrec bound tm
1527 | otherwise = text ("{{{V" ++ show i ++ "}}}")
1532 | otherwise = text ("{{{V" ++ show i ++ "}}}")
1528 pp p bound (Bind n b sc) = ppb p bound n b $
1533 pp p bound (Bind n b sc) = ppb p bound n b $
1529 pp startPrec (n:bound) sc
1534 pp startPrec (n:bound) sc
1530− pp p bound (App tm1 tm2) =
1535+ pp p bound (App _ tm1 tm2) =
1531 bracket p appPrec . group . hang 2 $
1536 bracket p appPrec . group . hang 2 $
1532 pp appPrec bound tm1 <> line <>
1537 pp appPrec bound tm1 <> line <>
1533 pp (appPrec + 1) bound tm2
1538 pp (appPrec + 1) bound tm2