-- undefined and holes
| Undef Loc Ter -- Location and type
- | Hole
+ | Hole Loc
-- Id type
| IdP Ter Ter Ter
isNeutral :: Val -> Bool
isNeutral v = case v of
Ter Undef{} _ -> True
+ Ter Hole{} _ -> True
VVar _ _ -> True
VFst v -> isNeutral v
VSnd v -> isNeutral v
Def ts e -> domainEnv e
Sub e (i,_) -> i : domainEnv e
+-- Extract the context from the environment, used when printing holes
+contextOfEnv :: Env -> [String]
+contextOfEnv rho = case rho of
+ Empty -> []
+ Upd e (x,v) -> (x ++ " : " ++ show v) : contextOfEnv e
+ Def ts e -> contextOfEnv e
+ Sub e (i,phi) -> (show i ++ " = " ++ show phi) : contextOfEnv e
+
--------------------------------------------------------------------------------
-- | Pretty printing
show = render . showLoc
showLoc :: Loc -> Doc
-showLoc (Loc name (i,j)) = hcat [text name,text "_L",int i,text "_C",int j]
+showLoc (Loc name (i,j)) = text (show (i,j) ++ " in " ++ name)
showFormula :: Formula -> Doc
showFormula phi = case phi of
showTers es <+> showFormula phi
Split f _ _ _ -> text f
Sum _ n _ -> text n
- Undef _ _ -> text "undefined"
- Hole -> text "?"
+ Undef{} -> text "undefined"
+ Hole{} -> text "?"
IdP e0 e1 e2 -> text "IdP" <+> showTers [e0,e1,e2]
Path i e -> char '<' <> text (show i) <> char '>' <+> showTer e
AppFormula e phi -> showTer1 e <+> char '@' <+> showFormula phi
Con c [] -> text c
Var{} -> showTer t
Undef{} -> showTer t
- Hole -> showTer t
+ Hole{} -> showTer t
Split{} -> showTer t
Sum{} -> showTer t
_ -> parens (showTer t)
(@@) :: ToFormula a => Val -> a -> Val
(VPath i u) @@ phi = u `act` (i,toFormula phi)
+v@(Ter Hole{} _) @@ phi = VAppFormula v (toFormula phi)
v @@ phi | isNeutral v = case (inferType v,toFormula phi) of
(VIdP _ a0 _,Dir 0) -> a0
(VIdP _ _ a1,Dir 1) -> a1
(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 Hole{} e,Ter Hole{} e') -> conv k e e'
+ (Ter Hole{} e,_) -> True
+ (_,Ter Hole{} e') -> True
(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)
Var. Exp5 ::= AIdent ;
PCon. Exp5 ::= AIdent "{" Exp "}" ; -- c{T A B} x1 x2 @ phi
U. Exp5 ::= "U" ;
-Hole. Exp5 ::= "?" ;
+Hole. Exp5 ::= HoleIdent ;
coercions Exp 5 ;
separator nonempty Exp "," ;
PTele. PTele ::= "(" Exp ":" Exp ")" ;
terminator nonempty PTele "" ;
-position token AIdent (letter|'_')(letter|digit|'\''|'_')* ;
+position token AIdent (letter|'_')(letter|digit|'\'')* ;
separator AIdent "" ;
-token CIdent '/''\\' ;
\ No newline at end of file
+token CIdent '/''\\' ;
+
+position token HoleIdent '?' ;
\ No newline at end of file
resolveExp :: Exp -> Resolver Ter
resolveExp e = case e of
U -> return CTT.U
- Hole -> return CTT.Hole
Var x -> resolveVar x
App t s -> resolveApps x xs
where (x,xs) = unApps t [s]
(rdecls,names) <- resolveDecls decls
CTT.mkWheres rdecls <$> local (insertIdents names) (resolveExp e)
Path is e -> paths is (resolveExp e)
+ Hole (HoleIdent (l,_)) -> CTT.Hole <$> getLoc l
AppFormula e phi ->
let (x,xs) = unApps e []
in case x of
check :: Val -> Ter -> Typing ()\r
check a t = case (a,t) of\r
(_,Undef{}) -> return ()\r
+ (_,Hole l) -> do\r
+ rho <- asks env\r
+ let e = unlines (reverse (contextOfEnv rho))\r
+ trace $ "\nHole at " ++ show l ++ ":\n\n" ++\r
+ e ++ replicate 80 '-' ++ "\n" ++ show a ++ "\n"\r
(_,Con c es) -> do\r
(bs,nu) <- getLblType c a\r
checks (bs,nu) es\r
check va u\r
vu <- evalTyping u\r
checkGlueElem vu ts us\r
- (_,Hole) -> do\r
- trace $ "Hole expects: " ++ show a\r
- return ()\r
_ -> do\r
v <- infer t\r
unlessM (v === a) $\r
infer e = case e of\r
U -> return VU -- U : U\r
Var n -> lookType n <$> asks env\r
--- Undef _ t -> evalTyping t\r
App t u -> do\r
c <- infer t\r
case c of\r