|
@ -199,13 +199,12 @@ check (P.LamCase pats) ty = do |
|
|
case porp of |
|
|
case porp of |
|
|
It'sProd dom rng wp -> do |
|
|
It'sProd dom rng wp -> do |
|
|
name <- newName |
|
|
name <- newName |
|
|
liftIO . print $ show pats |
|
|
|
|
|
cases <- for pats $ \(pat, rhs) -> do |
|
|
cases <- for pats $ \(pat, rhs) -> do |
|
|
checkPattern pat dom \pat wp -> do |
|
|
|
|
|
pat_nf <- eval pat |
|
|
|
|
|
|
|
|
checkPattern pat dom \pat wp pat_nf -> do |
|
|
rhs <- check rhs (rng pat_nf) |
|
|
rhs <- check rhs (rng pat_nf) |
|
|
pure (pat, wp rhs) |
|
|
pure (pat, wp rhs) |
|
|
pure (wp (Lam P.Ex name (Case (Ref name) cases))) |
|
|
|
|
|
|
|
|
let x = wp (Lam P.Ex name (Case (Ref name) cases)) |
|
|
|
|
|
pure x |
|
|
_ -> do |
|
|
_ -> do |
|
|
dom <- newMeta VTypeω |
|
|
dom <- newMeta VTypeω |
|
|
n <- newName' (Bound (T.singleton 'x') 0) |
|
|
n <- newName' (Bound (T.singleton 'x') 0) |
|
@ -218,29 +217,29 @@ check exp ty = do |
|
|
wp <- isConvertibleTo has ty |
|
|
wp <- isConvertibleTo has ty |
|
|
pure (wp tm) |
|
|
pure (wp tm) |
|
|
|
|
|
|
|
|
checkPattern :: P.Pattern -> NFSort -> (Term -> (Term -> Term) -> ElabM a) -> ElabM a |
|
|
|
|
|
|
|
|
checkPattern :: P.Pattern -> NFSort -> (Term -> (Term -> Term) -> Value -> ElabM a) -> ElabM a |
|
|
checkPattern (P.PCap var) dom cont = do |
|
|
checkPattern (P.PCap var) dom cont = do |
|
|
name <- asks (Map.lookup var . nameMap) |
|
|
name <- asks (Map.lookup var . nameMap) |
|
|
case name of |
|
|
case name of |
|
|
Just name@(ConName _ _ skip arity) -> do |
|
|
Just name@(ConName _ _ skip arity) -> do |
|
|
unless (arity == 0) $ throwElab $ UnsaturatedCon name |
|
|
unless (arity == 0) $ throwElab $ UnsaturatedCon name |
|
|
ty <- instantiate =<< getNfType name |
|
|
|
|
|
_ <- isConvertibleTo ty dom |
|
|
|
|
|
|
|
|
(ty, wp) <- instantiate =<< getNfType name |
|
|
|
|
|
unify ty dom |
|
|
wrap <- skipLams skip |
|
|
wrap <- skipLams skip |
|
|
cont (Con name) wrap |
|
|
|
|
|
|
|
|
cont (Con name) wrap =<< eval (wp (Con name)) |
|
|
Just name -> throwElab $ NotACon name |
|
|
Just name -> throwElab $ NotACon name |
|
|
Nothing -> assume (Bound var 0) dom \name -> cont (Ref name) (Lam P.Ex name) |
|
|
|
|
|
|
|
|
Nothing -> assume (Bound var 0) dom \name -> cont (Ref name) (Lam P.Ex name) (VVar name) |
|
|
checkPattern (P.PCon var args) dom cont = |
|
|
checkPattern (P.PCon var args) dom cont = |
|
|
do |
|
|
do |
|
|
name <- asks (Map.lookup var . nameMap) |
|
|
name <- asks (Map.lookup var . nameMap) |
|
|
case name of |
|
|
case name of |
|
|
Just name@(ConName _ _ nskip arity) -> do |
|
|
Just name@(ConName _ _ nskip arity) -> do |
|
|
unless (arity == length args) $ throwElab $ UnsaturatedCon name |
|
|
unless (arity == length args) $ throwElab $ UnsaturatedCon name |
|
|
ty <- instantiate =<< getNfType name |
|
|
|
|
|
|
|
|
(ty, wp) <- instantiate =<< getNfType name |
|
|
_ <- isConvertibleTo (skipBinders arity ty) dom |
|
|
_ <- isConvertibleTo (skipBinders arity ty) dom |
|
|
skip <- skipLams nskip |
|
|
skip <- skipLams nskip |
|
|
bindNames args ty $ \_ wrap -> |
|
|
|
|
|
cont (Con name) (skip . wrap) |
|
|
|
|
|
|
|
|
bindNames args ty $ \names wrap -> |
|
|
|
|
|
cont (Con name) (skip . wrap) =<< eval (foldl (\x y -> App P.Ex x (Ref y)) (wp (Con name)) names) |
|
|
Just name -> throwElab $ NotACon name |
|
|
Just name -> throwElab $ NotACon name |
|
|
_ -> throwElab $ NotInScope (Bound var 0) |
|
|
_ -> throwElab $ NotInScope (Bound var 0) |
|
|
where |
|
|
where |
|
@ -255,11 +254,12 @@ checkPattern (P.PCon var args) dom cont = |
|
|
bindNames [] _ k = k [] id |
|
|
bindNames [] _ k = k [] id |
|
|
bindNames xs t _ = error $ show (xs, t) |
|
|
bindNames xs t _ = error $ show (xs, t) |
|
|
|
|
|
|
|
|
instantiate :: NFType -> ElabM NFType |
|
|
|
|
|
|
|
|
instantiate :: NFType -> ElabM (NFType, Term -> Term) |
|
|
instantiate (VPi P.Im d (Closure _ k)) = do |
|
|
instantiate (VPi P.Im d (Closure _ k)) = do |
|
|
t <- newMeta d |
|
|
t <- newMeta d |
|
|
instantiate (k t) |
|
|
|
|
|
instantiate x = pure x |
|
|
|
|
|
|
|
|
(ty, w) <- instantiate (k t) |
|
|
|
|
|
pure (ty, \inner -> App P.Im (w inner) (quote t)) |
|
|
|
|
|
instantiate x = pure (x, id) |
|
|
|
|
|
|
|
|
skipLams :: Int -> ElabM (Term -> Term) |
|
|
skipLams :: Int -> ElabM (Term -> Term) |
|
|
skipLams 0 = pure id |
|
|
skipLams 0 = pure id |
|
@ -445,18 +445,20 @@ checkStatement (P.ReplTy e) k = do |
|
|
|
|
|
|
|
|
checkStatement (P.Data name tele retk constrs) k = |
|
|
checkStatement (P.Data name tele retk constrs) k = |
|
|
do |
|
|
do |
|
|
checkTeleRetk True tele retk \kind tele -> do |
|
|
|
|
|
|
|
|
checkTeleRetk True tele retk \kind tele undef -> do |
|
|
kind_nf <- eval kind |
|
|
kind_nf <- eval kind |
|
|
defineInternal (Bound name 0) kind_nf (\name' -> VNe (HData name') mempty) \name' -> do |
|
|
|
|
|
checkCons tele (VNe (HData name') (Seq.fromList (map makeProj tele))) constrs k |
|
|
|
|
|
|
|
|
defineInternal (Defined name 0) kind_nf (\name' -> VNe (HData name') mempty) \name' -> |
|
|
|
|
|
checkCons tele (VNe (HData name') (Seq.fromList (map makeProj tele))) constrs (local (markAsDef name' . undef) k) |
|
|
where |
|
|
where |
|
|
makeProj (x, p, _) = PApp p (VVar x) |
|
|
makeProj (x, p, _) = PApp p (VVar x) |
|
|
|
|
|
|
|
|
|
|
|
markAsDef x e = e { definedNames = Set.insert x (definedNames e) } |
|
|
|
|
|
|
|
|
checkTeleRetk allKan [] retk cont = do |
|
|
checkTeleRetk allKan [] retk cont = do |
|
|
t <- check retk VTypeω |
|
|
t <- check retk VTypeω |
|
|
t_nf <- eval t |
|
|
t_nf <- eval t |
|
|
when allKan $ unify t_nf VType |
|
|
when allKan $ unify t_nf VType |
|
|
cont t [] |
|
|
|
|
|
|
|
|
cont t [] id |
|
|
checkTeleRetk allKan ((x, p, t):xs) retk cont = do |
|
|
checkTeleRetk allKan ((x, p, t):xs) retk cont = do |
|
|
(t, ty) <- infer t |
|
|
(t, ty) <- infer t |
|
|
_ <- isConvertibleTo ty VTypeω |
|
|
_ <- isConvertibleTo ty VTypeω |
|
@ -465,7 +467,8 @@ checkStatement (P.Data name tele retk constrs) k = |
|
|
VType -> allKan |
|
|
VType -> allKan |
|
|
_ -> False |
|
|
_ -> False |
|
|
t_nf <- eval t |
|
|
t_nf <- eval t |
|
|
assume (Bound x 0) t_nf $ \nm -> checkTeleRetk allKan' xs retk \k xs -> cont (Pi p nm t k) ((nm, p, t_nf):xs) |
|
|
|
|
|
|
|
|
let rm nm e = e{ nameMap = Map.delete (getNameText nm) (nameMap e), getEnv = Map.delete nm (getEnv e) } |
|
|
|
|
|
assume (Bound x 0) t_nf $ \nm -> checkTeleRetk allKan' xs retk \k xs w -> cont (Pi p nm t k) ((nm, p, t_nf):xs) (rm nm . w) |
|
|
|
|
|
|
|
|
checkCons _ _et [] k = k |
|
|
checkCons _ _et [] k = k |
|
|
|
|
|
|
|
|