inferType :: Val -> Val
inferType v = case v of
VVar _ t -> t
- VFst t -> undefined
- VSnd t -> undefined
- VSplit t0 t1 -> undefined
- VApp t0 t1 -> undefined
- VAppFormula t phi -> undefined
+ VFst t -> case inferType t of
+ VSigma a _ -> a
+ _ -> error $ "inferType: not neutral " ++ show v
+ VSnd t -> case inferType t of
+ VSigma _ f -> app f (VFst t)
+ _ -> error $ "inferType: not neutral " ++ show v
+ VSplit t0 t1 -> case inferType t0 of
+ VPi _ f -> app f t1
+ _ -> error $ "inferType: not neutral " ++ show v
+ VApp t0 t1 -> case inferType t0 of
+ VPi _ f -> app f t1
+ _ -> error $ "inferType: not neutral " ++ show v
+ VAppFormula t phi -> case inferType t of
+ VIdP a _ _ -> a @@ phi
+ _ -> error $ "inferType: not neutral " ++ show v
(@@) :: ToFormula a => Val -> a -> Val
(VPath i u) @@ phi = u `act` (i,toFormula phi)
check b0 e0\r
check b1 e1\r
_ -> throwError ("IdP expects a path but got " ++ show a)\r
- (VIdP p a b,Path i e) -> do\r
+ (VIdP p a0 a1,Path i e) -> do\r
rho <- asks env\r
+ k <- asks index\r
when (i `elem` support rho)\r
(throwError (show i ++ " is already declared"))\r
local (addSub (i,Atom i)) $ check (p @@ i) e\r
+ let u0 = eval (Sub rho (i,Dir 0)) e\r
+ u1 = eval (Sub rho (i,Dir 1)) e\r
+ unless (conv k a0 u0 && conv k a1 u1) $\r
+ throwError $ "path endpoints don't match " ++ show e\r
_ -> do\r
v <- infer t\r
k <- index <$> ask\r