in isNeutralSystem (Map.filterWithKey testFace ts)
isNeutralComp _ _ _ = False
-mkVar :: Int -> Val -> Val
-mkVar k = VVar ('X' : show k)
+-- TODO: Use the String!
+mkVar :: Int -> String -> Val -> Val
+mkVar k x = VVar ("X_" ++ show k)
unCon :: Val -> [Val]
unCon (VCon _ vs) = vs
VLam x t e -> char '\\' <> parens (text x <+> colon <+> showVal t) <+>
text "->" <+> showVal e
VSplit u v -> showVal u <+> showVal1 v
- VVar x t -> text x
+ VVar x t | head x == '_' -> text x -- Special case, otherwise it is X_0
+ | otherwise -> text x -- text (takeWhile (/= '_') x)
VFst u -> showVal1 u <> text ".1"
VSnd u -> showVal1 u <> text ".2"
VIdP v0 v1 v2 -> text "IdP" <+> showVals [v0,v1,v2]
let j = fresh (u,v)
in case (simplify k j u, simplify k j v) of
(Ter (Lam x a u) e,Ter (Lam x' a' u') e') ->
- let v = mkVar k (eval e a)
+ let v = mkVar k x (eval e a)
in conv (k+1) (eval (Upd e (x,v)) u) (eval (Upd e' (x',v)) u')
(Ter (Lam x a u) e,u') ->
- let v = mkVar k (eval e a)
+ let v = mkVar k x (eval e a)
in conv (k+1) (eval (Upd e (x,v)) u) (app u' v)
(u',Ter (Lam x a u) e) ->
- let v = mkVar k (eval e a)
+ let v = mkVar k x (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 Hole{} e,_) -> True
(_,Ter Hole{} e') -> True
(VPi u v,VPi u' v') ->
- let w = mkVar k u
+ let w = mkVar k "X" u -- TODO: What string to put here?
in conv k u u' && conv (k+1) (app v w) (app v' w)
(VSigma u v,VSigma u' v') ->
- let w = mkVar k u
+ let w = mkVar k "X" u -- TODO: What string to put here?
in conv k u u' && conv (k+1) (app v w) (app v' w)
(VCon c us,VCon c' us') -> (c == c') && conv k us us'
(VPair u v,VPair u' v') -> conv k u u' && conv k v v'
normal _ VU = VU
normal k (Ter (Lam x t u) e) = VLam name w $ normal (k+1) (eval (Upd e (x,v)) u)
where w = eval e t
- v@(VVar name _) = mkVar k w
+ v@(VVar name _) = mkVar k x w
normal k (VPi u v) = VPi (normal k u) (normal k v)
normal k (VSigma u v) = VSigma (normal k u) (normal k v)
normal k (VPair u v) = VPair (normal k u) (normal k v)
-- Environment for type checker\r
data TEnv =\r
TEnv { index :: Int -- for de Bruijn levels\r
+ , indent :: Int\r
, env :: Env\r
, verbose :: Bool -- Should it be verbose and print what it typechecks?\r
} deriving (Eq,Show)\r
\r
verboseEnv, silentEnv :: TEnv\r
-verboseEnv = TEnv 0 Empty True\r
-silentEnv = TEnv 0 Empty False\r
+verboseEnv = TEnv 0 0 Empty True\r
+silentEnv = TEnv 0 0 Empty False\r
\r
-- Trace function that depends on the verbosity flag\r
trace :: String -> Typing ()\r
-- | Modifiers for the environment\r
\r
addTypeVal :: (Ident,Val) -> TEnv -> TEnv\r
-addTypeVal (x,a) (TEnv k rho v) =\r
- TEnv (k+1) (Upd rho (x,mkVar k a)) v\r
+addTypeVal (x,a) (TEnv k ind rho v) =\r
+ TEnv (k+1) ind (Upd rho (x,mkVar k (show a) a)) v\r
\r
addSub :: (Name,Formula) -> TEnv -> TEnv\r
-addSub iphi (TEnv k rho v) = TEnv k (Sub rho iphi) v\r
+addSub iphi (TEnv k ind rho v) = TEnv k ind (Sub rho iphi) v\r
\r
addType :: (Ident,Ter) -> TEnv -> Typing TEnv\r
-addType (x,a) tenv@(TEnv _ rho _) = return $ addTypeVal (x,eval rho a) tenv\r
+addType (x,a) tenv@(TEnv _ _ rho _) = return $ addTypeVal (x,eval rho a) tenv\r
\r
addBranch :: [(Ident,Val)] -> (Tele,Env) -> TEnv -> TEnv\r
-addBranch nvs (tele,env) (TEnv k rho v) =\r
- TEnv (k + length nvs) (upds rho nvs) v\r
+addBranch nvs (tele,env) (TEnv k ind rho v) =\r
+ TEnv (k + length nvs) ind (upds rho nvs) v\r
\r
addDecls :: [Decl] -> TEnv -> TEnv\r
-addDecls d (TEnv k rho v) = TEnv k (Def d rho) v\r
+addDecls d (TEnv k ind rho v) = TEnv k ind (Def d rho) v\r
\r
addTele :: Tele -> TEnv -> Typing TEnv\r
addTele xas lenv = foldM (flip addType) lenv xas\r
mkVars :: Int -> Tele -> Env -> [(Ident,Val)]\r
mkVars k [] _ = []\r
mkVars k ((x,a):xas) nu =\r
- let w = mkVar k (eval nu a)\r
+ let w = mkVar k (show a) (eval nu a)\r
in (x,w) : mkVars (k+1) xas (Upd nu (x,w))\r
\r
-- Construct a fuction "(_ : va) -> vb"\r
rho <- asks env\r
unlessM (a === eval rho a') $\r
throwError "check: lam types don't match"\r
- let var = mkVar k a\r
+ let var = mkVar k (show a) a\r
local (addTypeVal (x,a)) $ check (app f var) t\r
(VSigma a f, Pair t1 t2) -> do\r
check a t1\r
v <- evalTyping t1\r
check (app f v) t2\r
(_,Where e d) -> do\r
- checkDecls d\r
+ local (\tenv@TEnv{indent=i} -> tenv{indent=i + 2}) $ checkDecls d\r
local (addDecls d) $ check a e\r
(VU,IdP a e0 e1) -> do\r
(a0,a1) <- checkPath (constPath VU) a\r
checkDecls :: [Decl] -> Typing ()\r
checkDecls d = do\r
let (idents,tele,ters) = (declIdents d,declTele d,declTers d)\r
- trace ("Checking: " ++ unwords idents)\r
+ ind <- asks indent\r
+ trace (replicate ind ' ' ++ "Checking: " ++ unwords idents)\r
checkTele tele\r
local (addDecls d) $ do\r
rho <- asks env\r