VU -> VU
Ter t e -> Ter t (acti e)
VPi a f -> VPi (acti a) (acti f)
- VComp a v ts -> comp (acti a) (acti v) (acti ts)
+ VComp a v ts -> compLine (acti a) (acti v) (acti ts)
VIdP a u v -> VIdP (acti a) (acti u) (acti v)
VPath j v | j `notElem` sphi -> VPath j (acti v)
| otherwise -> VPath k (v `swap` (j,k))
where k = fresh (v, Atom i, phi)
- VTrans u v -> trans' (acti u) (acti v)
+ VTrans u v -> transLine (acti u) (acti v)
VSigma a f -> VSigma (acti a) (acti f)
VSPair u v -> VSPair (acti u) (acti v)
VFst u -> VFst (acti u)
Path i t ->
let j = fresh rho
in VPath j (eval (Sub rho (i,Atom j)) t)
- Trans u v -> trans' (eval rho u) (eval rho v)
+ Trans u v -> transLine (eval rho u) (eval rho v)
AppFormula e phi -> (eval rho e) @@ (evalFormula rho phi)
-
--- Comp
+ Comp a t0 ts -> compLine (eval rho a) (eval rho t0) (evalSystem rho ts)
evalFormula :: Env -> Formula -> Formula
evalFormula rho phi = case phi of
evals :: Env -> [(Ident,Ter)] -> [(Ident,Val)]
evals env bts = [ (b,eval env t) | (b,t) <- bts ]
+evalSystem :: Env -> System Ter -> System Val
+evalSystem rho = undefined -- Map.mapWithKey (\alpha -> eval (rho `face` alpha))
+
app :: Val -> Val -> Val
app (Ter (Lam x _ t) e) u = eval (Pair e (x,u)) t
app (Ter (Split _ _ nvs) e) (VCon name us) = case lookup name nvs of
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
+ VSplit (Ter (Split _ f _) rho) v1 -> app (eval rho f) v1
VApp t0 t1 -> case inferType t0 of
VPi _ f -> app f t1
_ -> error $ "inferType: not neutral " ++ show v
-----------------------------------------------------------
-- Transport
-trans' :: Val -> Val -> Val
-trans' u v = case u of
- VPath i u0 -> trans i u0 v
- u0 -> VTrans u0 v
+transLine :: Val -> Val -> Val
+transLine u v = trans i (u @@ i) v
+ where i = fresh (u,v)
trans :: Name -> Val -> Val -> Val
trans i v0 v1 = case (v0,v1) of
-----------------------------------------------------------
-- Composition
-comp :: Val -> Val -> System Val -> Val
-comp a u ts = error "comp"
+compLine :: Val -> Val -> System Val -> Val
+compLine a u ts = comp i (a @@ i) u (Map.map (@@ i) ts)
+ where i = fresh (a,u,ts)
+
-- compNeg a u ts = comp a u (ts `sym` i)
+comp :: Name -> Val -> Val -> System Val -> Val
+comp = undefined
genComp, genCompNeg :: Name -> Val -> Val -> System Val -> Val
genComp i a u ts | Map.null ts = trans i a u
-genComp i a u ts = comp ai1 (trans i a u) ts'
- where ai1 = a `face` (i ~> 1)
- j = fresh (a,Atom i,ts,u)
+genComp i a u ts = comp i ai1 (trans i a u) ts'
+ where ai1 = a `face` (i ~> 1)
+ j = fresh (a,Atom i,ts,u)
comp' alpha u = VPath i (trans j ((a `face` alpha) `disj` (i,j)) u)
ts' = Map.mapWithKey comp' ts
genCompNeg i a u ts = genComp i (a `sym` i) u (ts `sym` i)
-------------------------------------------------------------------------------
-- | Conversion
-
class Convertible a where
- conv :: Int -> a -> a -> Bool
+ conv :: Int -> a -> a -> Bool
isIndep :: (Nominal a, Convertible a) => Int -> Name -> a -> Bool
isIndep k i u = conv k u (u `face` (i ~> 0))
+isCompSystem :: (Nominal a, Convertible a) => Int -> System a -> Bool
+isCompSystem k ts = and [ conv k (getFace alpha beta) (getFace beta alpha)
+ | (alpha,beta) <- allCompatible (Map.keys ts) ]
+ where getFace a b = face (ts ! a) (b `minus` a)
+
instance Convertible Val where
conv k u v | u == v = True
| otherwise = let j = fresh (u,v) in case (u,v) of
import Data.Function\r
import Data.List\r
import Data.Maybe\r
+import Data.Map (Map,(!))\r
+import qualified Data.Map as Map\r
import Data.Monoid hiding (Sum)\r
import Control.Monad\r
import Control.Monad.Trans\r
addTele :: Tele -> TEnv -> Typing TEnv\r
addTele xas lenv = foldM (flip addType) lenv xas\r
\r
+faceEnv :: Face -> TEnv -> TEnv\r
+faceEnv alpha tenv = tenv{env=env tenv `face` alpha}\r
+\r
trace :: String -> Typing ()\r
trace s = do\r
b <- verbose <$> ask\r
case b of\r
VIdP (VPath _ VU) _ b1 -> return b1\r
_ -> throwError $ "transport expects a path but got " ++ show p\r
+ Comp a t0 ts -> do\r
+ check VU a\r
+ rho <- asks env\r
+ let va = eval rho a\r
+ check va t0\r
+\r
+ -- check rho alpha |- t_alpha : a alpha\r
+ sequence $ Map.elems $\r
+ Map.mapWithKey (\alpha talpha ->\r
+ local (faceEnv alpha) (check (va `face` alpha) talpha)) ts\r
+\r
+ -- check that the system is compatible\r
+ k <- asks index\r
+ unless (isCompSystem k (evalSystem rho ts))\r
+ (throwError ("Incompatible system " ++ show ts))\r
+ return va\r
_ -> throwError ("infer " ++ show e)\r
\r
+\r
-- Check that a term is a path and output the source and target\r
checkPath :: Ter -> Typing (Val,Val)\r
checkPath (Path i a) = do\r