@@ -58,6 +58,14 @@ isType ctxt env tm = isType' (normalise ctxt env tm)
58 where isType' tm | isUniverse tm = return ()
58 where isType' tm | isUniverse tm = return ()
59 | otherwise = fail (showEnv env tm ++ " is not a Type")
59 | otherwise = fail (showEnv env tm ++ " is not a Type")
61+convType :: Context -> Env -> Term -> StateT UCs TC ()
62+convType ctxt env tm =
65+ case normalise ctxt env tm of
67+ _ -> convertsC ctxt env tm (TType (UVar v))
61recheck :: Context -> Env -> Raw -> Term -> TC (Term, Type, UCs)
69recheck :: Context -> Env -> Raw -> Term -> TC (Term, Type, UCs)
62recheck = recheck_borrowing False []
70recheck = recheck_borrowing False []
@@ -175,6 +183,13 @@ check' holes ctxt env top = chk (TType (UVar (-5))) env top where
175 put (v+1, cs)
183 put (v+1, cs)
176 let maxu = UVar v
184 let maxu = UVar v
177 (tv, tt) <- chk st ((n, Pi i sv kv) : env) t
185 (tv, tt) <- chk st ((n, Pi i sv kv) : env) t
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)
178 case (normalise ctxt env st, normalise ctxt env tt) of
193 case (normalise ctxt env st, normalise ctxt env tt) of
179 (TType su, TType tu) -> do
194 (TType su, TType tu) -> do
180 when (not holes) $ do (v, cs) <- get
195 when (not holes) $ do (v, cs) <- get
@@ -210,63 +225,55 @@ check' holes ctxt env top = chk (TType (UVar (-5))) env top where
210 where checkBinder (Lam t)
225 where checkBinder (Lam t)
211 = do (tv, tt) <- chk u env t
226 = do (tv, tt) <- chk u env t
212 let tv' = normalise ctxt env tv
227 let tv' = normalise ctxt env tv
213− let tt' = normalise ctxt env tt
214− lift $ isType ctxt env tt'
228+ convType ctxt env tt
215− return (Lam tv, tt')
229+ return (Lam tv, tt)
216 checkBinder (Let t v)
230 checkBinder (Let t v)
217 = do (tv, tt) <- chk u env t
231 = do (tv, tt) <- chk u env t
218 (vv, vt) <- chk u env v
232 (vv, vt) <- chk u env v
219 let tv' = normalise ctxt env tv
233 let tv' = normalise ctxt env tv
220− let tt' = normalise ctxt env tt
221 convertsC ctxt env vt tv
234 convertsC ctxt env vt tv
222− lift $ isType ctxt env tt'
235+ convType ctxt env tt
223− return (Let tv vv, tt')
236+ return (Let tv vv, tt)
224 checkBinder (NLet t v)
237 checkBinder (NLet t v)
225 = do (tv, tt) <- chk u env t
238 = do (tv, tt) <- chk u env t
226 (vv, vt) <- chk u env v
239 (vv, vt) <- chk u env v
227 let tv' = normalise ctxt env tv
240 let tv' = normalise ctxt env tv
228− let tt' = normalise ctxt env tt
229 convertsC ctxt env vt tv
241 convertsC ctxt env vt tv
230− lift $ isType ctxt env tt'
242+ convType ctxt env tt
231− return (NLet tv vv, tt')
243+ return (NLet tv vv, tt)
232 checkBinder (Hole t)
244 checkBinder (Hole t)
233 | not holes = lift $ tfail (IncompleteTerm undefined)
245 | not holes = lift $ tfail (IncompleteTerm undefined)
234 | otherwise
246 | otherwise
235 = do (tv, tt) <- chk u env t
247 = do (tv, tt) <- chk u env t
236 let tv' = normalise ctxt env tv
248 let tv' = normalise ctxt env tv
237− let tt' = normalise ctxt env tt
238− lift $ isType ctxt env tt'
249+ convType ctxt env tt
239− return (Hole tv, tt')
250+ return (Hole tv, tt)
240 checkBinder (GHole i ns t)
251 checkBinder (GHole i ns t)
241 = do (tv, tt) <- chk u env t
252 = do (tv, tt) <- chk u env t
242 let tv' = normalise ctxt env tv
253 let tv' = normalise ctxt env tv
243− let tt' = normalise ctxt env tt
244− lift $ isType ctxt env tt'
254+ convType ctxt env tt
245− return (GHole i ns tv, tt')
255+ return (GHole i ns tv, tt)
246 checkBinder (Guess t v)
256 checkBinder (Guess t v)
247 | not holes = lift $ tfail (IncompleteTerm undefined)
257 | not holes = lift $ tfail (IncompleteTerm undefined)
248 | otherwise
258 | otherwise
249 = do (tv, tt) <- chk u env t
259 = do (tv, tt) <- chk u env t
250 (vv, vt) <- chk u env v
260 (vv, vt) <- chk u env v
251 let tv' = normalise ctxt env tv
261 let tv' = normalise ctxt env tv
252− let tt' = normalise ctxt env tt
253 convertsC ctxt env vt tv
262 convertsC ctxt env vt tv
254− lift $ isType ctxt env tt'
263+ convType ctxt env tt
255− return (Guess tv vv, tt')
264+ return (Guess tv vv, tt)
256 checkBinder (PVar t)
265 checkBinder (PVar t)
257 = do (tv, tt) <- chk u env t
266 = do (tv, tt) <- chk u env t
258 let tv' = normalise ctxt env tv
267 let tv' = normalise ctxt env tv
259− let tt' = normalise ctxt env tt
260− lift $ isType ctxt env tt'
268+ convType ctxt env tt
261 -- Normalised version, for erasure purposes (it's easier
269 -- Normalised version, for erasure purposes (it's easier
262 -- to tell if it's a collapsible variable)
270 -- to tell if it's a collapsible variable)
263− return (PVar tv, tt')
271+ return (PVar tv, tt)
264 checkBinder (PVTy t)
272 checkBinder (PVTy t)
265 = do (tv, tt) <- chk u env t
273 = do (tv, tt) <- chk u env t
266 let tv' = normalise ctxt env tv
274 let tv' = normalise ctxt env tv
267− let tt' = normalise ctxt env tt
268− lift $ isType ctxt env tt'
275+ convType ctxt env tt
269− return (PVTy tv, tt')
276+ return (PVTy tv, tt)
271 discharge n (Lam t) bt scv sct
278 discharge n (Lam t) bt scv sct
272 = return (Bind n (Lam t) scv, Bind n (Pi Nothing t bt) sct)
279 = return (Bind n (Lam t) scv, Bind n (Pi Nothing t bt) sct)