@@ -58,6 +58,14 @@ isType ctxt env tm = isType' (normalise ctxt env tm)
5858 where isType' tm | isUniverse tm = return ()
5959 | otherwise = fail (showEnv env tm ++ " is not a Type")
6060
61+convType :: Context -> Env -> Term -> StateT UCs TC ()
62+convType ctxt env tm =
63+ do (v, cs) <- get
64+ put (v + 1, cs)
65+ case normalise ctxt env tm of
66+ UType _ -> return ()
67+ _ -> convertsC ctxt env tm (TType (UVar v))
68+
6169recheck :: Context -> Env -> Raw -> Term -> TC (Term, Type, UCs)
6270recheck = recheck_borrowing False []
6371
@@ -175,6 +183,13 @@ check' holes ctxt env top = chk (TType (UVar (-5))) env top where
175183 put (v+1, cs)
176184 let maxu = UVar v
177185 (tv, tt) <- chk st ((n, Pi i sv kv) : env) t
186+
187+-- convertsC ctxt env st (TType maxu)
188+-- convertsC ctxt env tt (TType maxu)
189+-- when holes $ put (v, cs)
190+-- return (Bind n (Pi i (uniqueBinders (map fst env) sv) (TType maxu))
191+-- (pToV n tv), TType maxu)
192+
178193 case (normalise ctxt env st, normalise ctxt env tt) of
179194 (TType su, TType tu) -> do
180195 when (not holes) $ do (v, cs) <- get
@@ -210,63 +225,55 @@ check' holes ctxt env top = chk (TType (UVar (-5))) env top where
210225 where checkBinder (Lam t)
211226 = do (tv, tt) <- chk u env t
212227 let tv' = normalise ctxt env tv
213− let tt' = normalise ctxt env tt
214− lift $ isType ctxt env tt'
215− return (Lam tv, tt')
228+ convType ctxt env tt
229+ return (Lam tv, tt)
216230 checkBinder (Let t v)
217231 = do (tv, tt) <- chk u env t
218232 (vv, vt) <- chk u env v
219233 let tv' = normalise ctxt env tv
220− let tt' = normalise ctxt env tt
221234 convertsC ctxt env vt tv
222− lift $ isType ctxt env tt'
223− return (Let tv vv, tt')
235+ convType ctxt env tt
236+ return (Let tv vv, tt)
224237 checkBinder (NLet t v)
225238 = do (tv, tt) <- chk u env t
226239 (vv, vt) <- chk u env v
227240 let tv' = normalise ctxt env tv
228− let tt' = normalise ctxt env tt
229241 convertsC ctxt env vt tv
230− lift $ isType ctxt env tt'
231− return (NLet tv vv, tt')
242+ convType ctxt env tt
243+ return (NLet tv vv, tt)
232244 checkBinder (Hole t)
233245 | not holes = lift $ tfail (IncompleteTerm undefined)
234246 | otherwise
235247 = do (tv, tt) <- chk u env t
236248 let tv' = normalise ctxt env tv
237− let tt' = normalise ctxt env tt
238− lift $ isType ctxt env tt'
239− return (Hole tv, tt')
249+ convType ctxt env tt
250+ return (Hole tv, tt)
240251 checkBinder (GHole i ns t)
241252 = do (tv, tt) <- chk u env t
242253 let tv' = normalise ctxt env tv
243− let tt' = normalise ctxt env tt
244− lift $ isType ctxt env tt'
245− return (GHole i ns tv, tt')
254+ convType ctxt env tt
255+ return (GHole i ns tv, tt)
246256 checkBinder (Guess t v)
247257 | not holes = lift $ tfail (IncompleteTerm undefined)
248258 | otherwise
249259 = do (tv, tt) <- chk u env t
250260 (vv, vt) <- chk u env v
251261 let tv' = normalise ctxt env tv
252− let tt' = normalise ctxt env tt
253262 convertsC ctxt env vt tv
254− lift $ isType ctxt env tt'
255− return (Guess tv vv, tt')
263+ convType ctxt env tt
264+ return (Guess tv vv, tt)
256265 checkBinder (PVar t)
257266 = do (tv, tt) <- chk u env t
258267 let tv' = normalise ctxt env tv
259− let tt' = normalise ctxt env tt
260− lift $ isType ctxt env tt'
268+ convType ctxt env tt
261269 -- Normalised version, for erasure purposes (it's easier
262270 -- to tell if it's a collapsible variable)
263− return (PVar tv, tt')
271+ return (PVar tv, tt)
264272 checkBinder (PVTy t)
265273 = do (tv, tt) <- chk u env t
266274 let tv' = normalise ctxt env tv
267− let tt' = normalise ctxt env tt
268− lift $ isType ctxt env tt'
269− return (PVTy tv, tt')
275+ convType ctxt env tt
276+ return (PVTy tv, tt)
270277
271278 discharge n (Lam t) bt scv sct
272279 = return (Bind n (Lam t) scv, Bind n (Pi Nothing t bt) sct)