support (VCon _ vs) = support vs
support (VPCon _ a vs phi) = support (a,vs,phi)
support (VVar _ v) = support v
+ support (VUndef _ v) = support v
support (VApp u v) = support (u,v)
support (VLam _ u v) = support (u,v)
support (VAppFormula u phi) = support (u,phi)
VCon c vs -> VCon c (acti vs)
VPCon c a vs phi -> pcon c (acti a) (acti vs) (acti phi)
VVar x v -> VVar x (acti v)
+ VUndef x v -> VUndef x (acti v)
VAppFormula u psi -> acti u @@ acti psi
VApp u v -> app (acti u) (acti v)
VLam x t u -> VLam x (acti t) (acti u)
VCon c vs -> VCon c (sw vs)
VPCon c a vs phi -> VPCon c (sw a) (sw vs) (sw phi)
VVar x v -> VVar x (sw v)
+ VUndef x v -> VUndef x (sw v)
VAppFormula u psi -> VAppFormula (sw u) (sw psi)
VApp u v -> VApp (sw u) (sw v)
VLam x u v -> VLam x (sw u) (sw v)
eval :: Env -> Ter -> Val
eval rho v = case v of
- Undef{} -> Ter v rho
U -> VU
App r s -> app (eval rho r) (eval rho s)
Var i -> look i rho
+ Undef l t -> VUndef l (eval rho t)
Pi t@(Lam _ a _) -> VPi (eval rho a) (eval rho t)
Lam{} -> Ter v rho
Sigma t@(Lam _ a _) -> VSigma (eval rho a) (eval rho t)
inferType :: Val -> Val
inferType v = case v of
VVar _ t -> t
+ VUndef _ t -> t
VFst t -> case inferType t of
VSigma a _ -> a
ty -> error $ "inferType: expected Sigma type for " ++ show v
let v = mkVar k (eval e a)
in conv (k+1) (app u' v) (eval (Upd e (x,v)) u)
(Ter (Split _ p _ _) e,Ter (Split _ p' _ _) e') -> (p == p') && conv k e e'
- (Ter (Sum p _ _) e,Ter (Sum p' _ _) e') -> (p == p') && conv k e e'
- (Ter (Undef p) e,Ter (Undef p') e') -> (p == p') && conv k e e'
+ (Ter (Sum p _ _) e,Ter (Sum p' _ _) e') -> (p == p') && conv k e e'
+ (VUndef p _,VUndef p' _) -> p == p'
(VPi u v,VPi u' v') ->
let w = mkVar k u
in conv k u u' && conv (k+1) (app v w) (app v' w)
insertIdent :: (Ident,SymKind) -> Env -> Env
insertIdent (n,var) e
- | n == "_" || n == "undefined" = e
- | otherwise = e{variables = (n,var) : variables e}
+ | n == "_" = e
+ | otherwise = e{variables = (n,var) : variables e}
insertIdents :: [(Ident,SymKind)] -> Env -> Env
insertIdents = flip $ foldr insertIdent
getLoc :: (Int,Int) -> Resolver CTT.Loc
getLoc l = CTT.Loc <$> asks envModule <*> pure l
--- noLoc :: AIdent
--- noLoc = AIdent ((0,0),"_")
-
--- resolveAIdent :: AIdent -> Resolver (Ident,CTT.Loc)
--- resolveAIdent (AIdent (l,x)) = (x,) <$> getLoc l
-
unAIdent :: AIdent -> Ident
unAIdent (AIdent (_,x)) = x
show l ++ " in module " ++ modName
resolveVar :: AIdent -> Resolver Ter
-resolveVar (AIdent (l,x))
- | (x == "_") || (x == "undefined") = CTT.Undef <$> getLoc l
- | otherwise = do
- modName <- asks envModule
- vars <- asks variables
- case lookup x vars of
- Just Variable -> return $ CTT.Var x
- Just Constructor -> return $ CTT.Con x []
- Just PConstructor -> throwError $ "The path constructor " ++ x ++ " is used as a"
- ++ " variable at " ++ show l ++ " in " ++ modName
- ++ " (path constructors should have their type in"
- ++ " curly braces as first argument)"
- Just Name ->
- throwError $ "Name " ++ x ++ " used as a variable at position " ++
- show l ++ " in module " ++ modName
- _ -> throwError $ "Cannot resolve variable " ++ x ++ " at position " ++
- show l ++ " in module " ++ modName
+resolveVar (AIdent (l,x)) = do
+ modName <- asks envModule
+ vars <- asks variables
+ case lookup x vars of
+ Just Variable -> return $ CTT.Var x
+ Just Constructor -> return $ CTT.Con x []
+ Just PConstructor -> throwError $ "The path constructor " ++ x ++ " is used as a"
+ ++ " variable at " ++ show l ++ " in " ++ modName
+ ++ " (path constructors should have their type in"
+ ++ " curly braces as first argument)"
+ Just Name ->
+ throwError $ "Name " ++ x ++ " used as a variable at position " ++
+ show l ++ " in module " ++ modName
+ _ -> throwError $ "Cannot resolve variable " ++ x ++ " at position " ++
+ show l ++ " in module " ++ modName
lam :: (Ident,Exp) -> Resolver Ter -> Resolver Ter
lam (a,t) e = CTT.Lam a <$> resolveExp t <*> local (insertVar a) e
resolveDir Dir1 = return 1
resolveFormula :: Formula -> Resolver C.Formula
-resolveFormula (Dir d) = C.Dir <$> resolveDir d
-resolveFormula (Atom i) = C.Atom <$> resolveName i
-resolveFormula (Neg phi) = C.negFormula <$> resolveFormula phi
-resolveFormula (Conj phi _ psi) = C.andFormula <$> resolveFormula phi
- <*> resolveFormula psi
-resolveFormula (Disj phi psi) = C.orFormula <$> resolveFormula phi
- <*> resolveFormula psi
+resolveFormula (Dir d) = C.Dir <$> resolveDir d
+resolveFormula (Atom i) = C.Atom <$> resolveName i
+resolveFormula (Neg phi) = C.negFormula <$> resolveFormula phi
+resolveFormula (Conj phi _ psi) =
+ C.andFormula <$> resolveFormula phi <*> resolveFormula psi
+resolveFormula (Disj phi psi) =
+ C.orFormula <$> resolveFormula phi <*> resolveFormula psi
resolveBranch :: Branch -> Resolver CTT.Branch
resolveBranch (OBranch (AIdent (_,lbl)) args e) = do
brs' <- local (insertVars (f:vars)) (mapM resolveBranch brs)
body <- lams tele' (return $ CTT.Split f loc ty brs')
return ((f,(a,body)),[(f,Variable)])
+ DeclUndef (AIdent (l,f)) tele t -> do
+ let tele' = flattenTele tele
+ a <- binds CTT.Pi tele' (resolveExp t)
+ d <- CTT.Undef <$> getLoc l <*> pure a
+ return ((f,(a,d)),[(f,Variable)])
resolveDecls :: [Decl] -> Resolver ([[CTT.Decl]],[(Ident,SymKind)])
resolveDecls [] = return ([],[])
resolveDecls (d:ds) = do
- (rtd,names) <- resolveDecl d
- (rds,names') <- local (insertIdents names) $ resolveDecls ds
- return ([rtd] : rds, names' ++ names)
+ (rtd,names) <- resolveDecl d
+ (rds,names') <- local (insertIdents names) $ resolveDecls ds
+ return ([rtd] : rds, names' ++ names)
resolveModule :: Module -> Resolver ([[CTT.Decl]],[(Ident,SymKind)])
resolveModule (Module (AIdent (_,n)) _ decls) =