| Glue Ter (System Ter)
| GlueElem Ter (System Ter)
| UnGlueElem Ter (System Ter)
+ -- Eq
+ | Eq Ter Ter Ter
+ | EqPair Ter (System Ter)
+ | EqJ Ter Ter Ter Ter Ter Ter
deriving Eq
-- For an expression t, returns (u,ts) where u is no application and t = u ts
-- Composition for HITs; the type is constant
| VHComp Val Val (System Val)
+ -- Eq
+ | VEq Val Val Val
+ | VEqPair Val (System Val)
+
-- Neutral values:
| VVar Ident Val
| VOpaque Ident Val
| VAppFormula Val Formula
| VLam Ident Val Val
| VUnGlueElemU Val Val (System Val)
+ | VEqJ Val Val Val Val Val Val
deriving Eq
isNeutral :: Val -> Bool
isNeutral v = case v of
- Ter Undef{} _ -> True
- Ter Hole{} _ -> True
- VVar{} -> True
- VOpaque{} -> True
- VComp{} -> True
- VFst{} -> True
- VSnd{} -> True
- VSplit{} -> True
- VApp{} -> True
- VAppFormula{} -> True
- VUnGlueElemU{} -> True
- VUnGlueElem{} -> True
- _ -> False
+ Ter Undef{} _ -> True
+ Ter Hole{} _ -> True
+ VVar{} -> True
+ VOpaque{} -> True
+ VComp{} -> True
+ VFst{} -> True
+ VSnd{} -> True
+ VSplit{} -> True
+ VApp{} -> True
+ VAppFormula{} -> True
+ VUnGlueElemU{} -> True
+ VUnGlueElem{} -> True
+ VEqJ{} -> True
+ _ -> False
isNeutralSystem :: System Val -> Bool
isNeutralSystem = any isNeutral . elems
Glue a ts -> text "Glue" <+> showTer1 a <+> text (showSystem ts)
GlueElem a ts -> text "glue" <+> showTer1 a <+> text (showSystem ts)
UnGlueElem a ts -> text "unglue" <+> showTer1 a <+> text (showSystem ts)
+ Eq a u v -> text "Eq" <+> showTers [a,u,v]
+ EqPair b ts -> text "eqC" <+> showTer1 b <+> text (showSystem ts)
+ EqJ a t c d x p -> text "eqJ" <+> showTers [a,t,c,d,x,p]
showTers :: [Ter] -> Doc
showTers = hsep . map showTer1
VUnGlueElem a ts -> support (a,ts)
VCompU a ts -> support (a,ts)
VUnGlueElemU a b es -> support (a,b,es)
+ VEqPair u us -> support (u,us)
+ VEq a u v -> support (a,u,v)
+ VEqJ a u c d x p -> support [a,u,c,d,x,p]
act u (i, phi) | i `notElem` support u = u
| otherwise =
VUnGlueElem a ts -> unglueElem (acti a) (acti ts)
VUnGlueElemU a b es -> unGlueU (acti a) (acti b) (acti es)
VCompU a ts -> compUniv (acti a) (acti ts)
+ VEqPair u us -> VEqPair (acti u) (acti us)
+ VEq a u v -> VEq (acti a) (acti u) (acti v)
+ VEqJ a u c d x p ->
+ eqJ (acti a) (acti u) (acti c) (acti d) (acti x) (acti p)
-- This increases efficiency as it won't trigger computation.
swap u ij@(i,j) =
VUnGlueElem a ts -> VUnGlueElem (sw a) (sw ts)
VUnGlueElemU a b es -> VUnGlueElemU (sw a) (sw b) (sw es)
VCompU a ts -> VCompU (sw a) (sw ts)
-
+ VEqPair u us -> VEqPair (sw u) (sw us)
+ VEq a u v -> VEq (sw a) (sw u) (sw v)
+ VEqJ a u c d x p ->
+ VEqJ (sw a) (sw u) (sw c) (sw d) (sw x) (sw p)
-----------------------------------------------------------------------
-- The evaluator
Glue a ts -> glue (eval rho a) (evalSystem rho ts)
GlueElem a ts -> glueElem (eval rho a) (evalSystem rho ts)
UnGlueElem a ts -> unglueElem (eval rho a) (evalSystem rho ts)
+ Eq a r s -> VEq (eval rho a) (eval rho r) (eval rho s)
+ EqPair b ts -> VEqPair (eval rho b) (evalSystem rho ts)
+ EqJ a t c d x p -> eqJ (eval rho a) (eval rho t) (eval rho c)
+ (eval rho d) (eval rho x) (eval rho p)
_ -> error $ "Cannot evaluate " ++ show v
evals :: Env -> [(Ident,Ter)] -> [(Ident,Val)]
VComp a _ _ -> a @@ One
-- VUnGlueElem _ b _ -> b -- This is wrong! Store the type??
VUnGlueElemU _ b _ -> b
+ VEqJ _ _ c _ x p -> app (app c x) p
_ -> error $ "inferType: not neutral " ++ show v
(@@) :: ToFormula a => Val -> a -> Val
VPathP p v0 v1 -> let j = fresh (Atom i,a,u,ts)
in VPLam j $ comp i (p @@ j) (u @@ j) $
insertsSystem [(j ~> 0,v0),(j ~> 1,v1)] (Map.map (@@ j) ts)
+ VEq b v0 v1 -> case u of
+ VEqPair r _ | all isEqPair (elems ts) ->
+ let j = fresh (Atom i,a,u,ts)
+ VEqPair z _ @@@ phi = z @@ phi
+ sys (VEqPair _ ws) = ws
+ w = VPLam j $ comp i b (r @@ j) $
+ insertsSystem [(j ~> 0,v0),(j ~> 1,v1)]
+ (Map.map (@@@ j) ts)
+ in VEqPair w (joinSystem (Map.map sys (ts `face` (i ~> 1))))
+ _ -> VComp (VPLam i a) u (Map.map (VPLam i) ts)
VSigma a f -> VPair ui1 comp_u2
where (t1s, t2s) = (Map.map fstVal ts, Map.map sndVal ts)
(u1, u2) = (fstVal u, sndVal u)
us' = [ (mkSystem [(i ~> 1, u `face` (i ~> 1))],u) | u <- us ]
+-------------------------------------------------------------------------------
+-- | Eq
+
+eqJ :: Val -> Val -> Val -> Val -> Val -> Val -> Val
+eqJ a v c d x p = case p of
+ VEqPair w ws -> comp i (app (app c (w @@ i)) w') d
+ (border d (shape ws))
+ where w' = VEqPair (VPLam j $ w @@ (Atom i :/\: Atom j))
+ (insertSystem (i ~> 0) v ws)
+ i:j:_ = freshs [a,v,c,d,x,p]
+ _ -> VEqJ a v c d x p
+
+isEqPair :: Val -> Bool
+isEqPair VEqPair{} = True
+isEqPair _ = False
+
+
-------------------------------------------------------------------------------
-- | HITs
(VUnGlueElemU u _ _,VUnGlueElemU u' _ _) -> conv ns u u'
(VUnGlueElem u ts,VUnGlueElem u' ts') -> conv ns (u,ts) (u',ts')
(VCompU u es,VCompU u' es') -> conv ns (u,es) (u',es')
- _ -> False
+ (VEqPair v vs,VEqPair v' vs') -> conv ns (v,vs) (v',vs')
+ (VEq a u v,VEq a' u' v') -> conv ns (a,u,v) (a',u',v')
+ (VEqJ a u c d x p,VEqJ a' u' c' d' x' p') ->
+ conv ns [a,u,c,d,x,p] [a',u',c',d',x',p']
+ _ -> False
instance Convertible Ctxt where
conv _ _ _ = True
VSplit u t -> VSplit (normal ns u) (normal ns t)
VApp u v -> app (normal ns u) (normal ns v)
VAppFormula u phi -> VAppFormula (normal ns u) (normal ns phi)
+ VEq a u v -> VEq (normal ns a) (normal ns u) (normal ns v)
+ VEqPair u us -> VEqPair (normal ns u) (normal ns us)
+ VEqJ a u c d x p -> eqJ (normal ns a) (normal ns u) (normal ns c)
+ (normal ns d) (normal ns x) (normal ns p)
_ -> v
instance Normal (Nameless a) where
check va u\r
vu <- evalTyping u\r
checkGlueElemU vu ves us\r
+ (VU,Eq a a0 a1) -> do\r
+ check VU a\r
+ va <- evalTyping a\r
+ check va a0\r
+ check va a1\r
+ (VEq va va0 va1,EqPair w ts) -> do\r
+ check (VPathP (constPath va) va0 va1) w\r
+ vw <- evalTyping w\r
+ checkSystemWith ts $ \alpha tAlpha ->\r
+ local (faceEnv alpha) $ do\r
+ check (va `face` alpha) tAlpha\r
+ vtAlpha <- evalTyping tAlpha\r
+ unlessM (vw `face` alpha === constPath vtAlpha) $\r
+ throwError "malformed eqC"\r
+ rho <- asks env\r
+ checkCompSystem (evalSystem rho ts) -- Not needed\r
_ -> do\r
v <- infer t\r
unlessM (v === a) $\r
checkEquiv :: Val -> Ter -> Typing ()\r
checkEquiv va equiv = check (mkEquiv va) equiv\r
\r
+checkIso :: Val -> Ter -> Typing ()\r
+checkIso vb iso = check (mkIso vb) iso\r
\r
checkBranch :: (Label,Env) -> Val -> Branch -> Val -> Val -> Typing ()\r
checkBranch (OLabel _ tele,nu) f (OBranch c ns e) _ _ = do\r
checks (bs,nu) es\r
mapM_ checkFormula phis\r
return va\r
+ EqJ a u c d x p -> do\r
+ check VU a\r
+ va <- evalTyping a\r
+ check va u\r
+ vu <- evalTyping u\r
+ let refu = VEqPair (constPath vu) $ mkSystem [(eps,vu)]\r
+ rho <- asks env\r
+ let z = Var "z"\r
+ ctype = eval rho $ Pi $ Lam "z" a $ Pi $ Lam "_" (Eq a u z) U\r
+ check ctype c\r
+ vc <- evalTyping c\r
+ check (app (app vc vu) refu) d\r
+ check va x\r
+ vx <- evalTyping x\r
+ check (VEq va vu vx) p\r
+ vp <- evalTyping p\r
+ return (app (app vc vx) vp)\r
_ -> throwError ("infer " ++ show e)\r
\r
-- Not used since we have U : U\r