|
@ -25,7 +25,6 @@ import Syntax.Pretty (prettyTm) |
|
|
import Syntax |
|
|
import Syntax |
|
|
|
|
|
|
|
|
import System.IO.Unsafe |
|
|
import System.IO.Unsafe |
|
|
import Syntax.Subst |
|
|
|
|
|
|
|
|
|
|
|
wiType :: WiredIn -> NFType |
|
|
wiType :: WiredIn -> NFType |
|
|
wiType WiType = VType |
|
|
wiType WiType = VType |
|
@ -94,6 +93,9 @@ fun, line :: (Value -> Value) -> Value |
|
|
fun k = VLam P.Ex $ Closure (Bound "x" 0) (k . force) |
|
|
fun k = VLam P.Ex $ Closure (Bound "x" 0) (k . force) |
|
|
line k = VLam P.Ex $ Closure (Bound "i" 0) (k . force) |
|
|
line k = VLam P.Ex $ Closure (Bound "i" 0) (k . force) |
|
|
|
|
|
|
|
|
|
|
|
fun' :: String -> (Value -> Value) -> Value |
|
|
|
|
|
fun' x k = VLam P.Ex $ Closure (Bound (T.pack x) 0) (k . force) |
|
|
|
|
|
|
|
|
forallI :: (Value -> Value) -> Value |
|
|
forallI :: (Value -> Value) -> Value |
|
|
forallI k = VLam P.Im $ Closure (Bound "x" 0) (k . force) |
|
|
forallI k = VLam P.Im $ Closure (Bound "x" 0) (k . force) |
|
|
|
|
|
|
|
@ -196,7 +198,7 @@ ielim line left right fn i = |
|
|
VNe n sp -> VNe n (sp Seq.:|> PIElim line left right i) |
|
|
VNe n sp -> VNe n (sp Seq.:|> PIElim line left right i) |
|
|
VSystem map -> VSystem (fmap (flip (ielim line left right) i) map) |
|
|
VSystem map -> VSystem (fmap (flip (ielim line left right) i) map) |
|
|
VInc (VPath _ _ _) _ u -> ielim line left right u i |
|
|
VInc (VPath _ _ _) _ u -> ielim line left right u i |
|
|
VCase r x xs -> VCase r x (fmap (fmap (flip (IElim (quote line) (quote left) (quote right)) (quote i))) xs) |
|
|
|
|
|
|
|
|
VCase env r x xs -> VCase env r x (fmap (fmap (flip (IElim (quote line) (quote left) (quote right)) (quote i))) xs) |
|
|
_ -> error $ "can't ielim " ++ show (prettyTm (quote fn)) |
|
|
_ -> error $ "can't ielim " ++ show (prettyTm (quote fn)) |
|
|
|
|
|
|
|
|
outS :: HasCallStack => NFSort -> NFEndp -> Value -> Value -> Value |
|
|
outS :: HasCallStack => NFSort -> NFEndp -> Value -> Value -> Value |
|
@ -207,11 +209,12 @@ outS _ VI0 _ x = x |
|
|
|
|
|
|
|
|
outS a phi u (GluedVl x sp vl) = GluedVl x (sp Seq.:|> POuc a phi u) (outS a phi u vl) |
|
|
outS a phi u (GluedVl x sp vl) = GluedVl x (sp Seq.:|> POuc a phi u) (outS a phi u vl) |
|
|
outS a phi u (VNe x sp) = VNe x (sp Seq.:|> POuc a phi u) |
|
|
outS a phi u (VNe x sp) = VNe x (sp Seq.:|> POuc a phi u) |
|
|
|
|
|
outS a phi u (VSystem fs) = VSystem (fmap (outS a phi u) fs) |
|
|
outS _ _ _ v = error $ "can't outS " ++ show (prettyTm (quote v)) |
|
|
outS _ _ _ v = error $ "can't outS " ++ show (prettyTm (quote v)) |
|
|
|
|
|
|
|
|
-- Composition |
|
|
-- Composition |
|
|
comp :: NFLine -> NFEndp -> Value -> Value -> Value |
|
|
|
|
|
comp _a VI1 u _a0 = u @@ VI1 @@ VItIsOne |
|
|
|
|
|
|
|
|
comp :: HasCallStack => NFLine -> NFEndp -> Value -> Value -> Value |
|
|
|
|
|
comp _a VI1 u _a0 = u @@ VI1 @@ VItIsOne |
|
|
comp a psi@phi u incA0@(compOutS (a @@ VI1) phi (u @@ VI1 @@ VItIsOne) -> a0) = |
|
|
comp a psi@phi u incA0@(compOutS (a @@ VI1) phi (u @@ VI1 @@ VItIsOne) -> a0) = |
|
|
case force $ a @@ VVar (Bound (T.pack "i") (negate 1)) of |
|
|
case force $ a @@ VVar (Bound (T.pack "i") (negate 1)) of |
|
|
VPi{} -> |
|
|
VPi{} -> |
|
@ -252,28 +255,29 @@ comp a psi@phi u incA0@(compOutS (a @@ VI1) phi (u @@ VI1 @@ VItIsOne) -> a0) = |
|
|
, (inot j, u' i)])) |
|
|
, (inot j, u' i)])) |
|
|
(VInc (a' VI0 @@ VI0 @@ j) phi (ielim (a' VI0 @@ VI0) (u' VI0) (v' VI0) a0 j)) |
|
|
(VInc (a' VI0 @@ VI0 @@ j) phi (ielim (a' VI0 @@ VI0) (u' VI0) (v' VI0) a0 j)) |
|
|
|
|
|
|
|
|
VGlueTy theBase thePhi theTypes theEquivs -> |
|
|
|
|
|
|
|
|
VGlueTy _ thePhi theTypes theEquivs -> |
|
|
let |
|
|
let |
|
|
b = u |
|
|
b = u |
|
|
b0 = a0 |
|
|
b0 = a0 |
|
|
|
|
|
fam = a |
|
|
in |
|
|
in |
|
|
let |
|
|
let |
|
|
base i = substitute (Map.singleton (Bound "i" (negate 1)) i) theBase |
|
|
|
|
|
|
|
|
base i = let VGlueTy b _ _ _ = forceAndGlue (fam @@ i) in b |
|
|
phi i = substitute (Map.singleton (Bound "i" (negate 1)) i) thePhi |
|
|
phi i = substitute (Map.singleton (Bound "i" (negate 1)) i) thePhi |
|
|
types i = substitute (Map.singleton (Bound "i" (negate 1)) i) theTypes |
|
|
|
|
|
|
|
|
types i = substitute (Map.singleton (Bound "i" (negate 1)) i) theTypes @@ VItIsOne |
|
|
equivs i = substitute (Map.singleton (Bound "i" (negate 1)) i) theEquivs |
|
|
equivs i = substitute (Map.singleton (Bound "i" (negate 1)) i) theEquivs |
|
|
|
|
|
|
|
|
a i = fun \u -> unglue (base i) (phi i) (types i @@ u) (equivs i @@ u) (b @@ i @@ u) |
|
|
|
|
|
|
|
|
a i u = unglue (base i) (phi i) (types i @@ u) (equivs i) (b @@ i @@ u) |
|
|
a0 = unglue (base VI0) (phi VI0) (types VI0) (equivs VI0) b0 |
|
|
a0 = unglue (base VI0) (phi VI0) (types VI0) (equivs VI0) b0 |
|
|
|
|
|
|
|
|
del = faceForall phi |
|
|
del = faceForall phi |
|
|
a1' = comp (line base) psi (line a) (VInc (base VI0) (phi VI0) a0) |
|
|
|
|
|
t1' = comp (line types) psi (line (b @@)) (VInc (base VI0) (phi VI0) b0) |
|
|
|
|
|
|
|
|
a1' = comp (line base) psi (system a) (VInc (base VI0) psi a0) |
|
|
|
|
|
t1' = comp (line (const (types VI0))) psi (line (b @@)) (VInc (base VI0) psi b0) |
|
|
|
|
|
|
|
|
(omega_st, omega_t, omega_rep) = pres types base equivs psi (b @@) b0 |
|
|
(omega_st, omega_t, omega_rep) = pres types base equivs psi (b @@) b0 |
|
|
omega = outS omega_t psi omega_rep omega_st |
|
|
omega = outS omega_t psi omega_rep omega_st |
|
|
|
|
|
|
|
|
(t1alpha_st, t1a_t, t1a_rep) = opEquiv (base VI1) (types VI1 @@ VItIsOne) (equivs VI1 @@ VItIsOne) (del `ior` psi) (fun ts) (fun ps) a1' |
|
|
|
|
|
|
|
|
(t1alpha_st, t1a_t, t1a_rep) = opEquiv (base VI1) (types VI1) (equivs VI1 @@ VItIsOne) (del `ior` psi) (fun ts) (fun ps) a1' |
|
|
t1alpha = outS t1a_t (del `ior` psi) t1a_rep t1alpha_st |
|
|
t1alpha = outS t1a_t (del `ior` psi) t1a_rep t1alpha_st |
|
|
|
|
|
|
|
|
(t1, alpha) = (vProj1 t1alpha, vProj2 t1alpha) |
|
|
(t1, alpha) = (vProj1 t1alpha, vProj2 t1alpha) |
|
@ -282,17 +286,18 @@ comp a psi@phi u incA0@(compOutS (a @@ VI1) phi (u @@ VI1 @@ VItIsOne) -> a0) = |
|
|
ps _isone = mkVSystem . Map.fromList $ [(del, omega), (psi, VLine (line (const (base VI1))) a1' a1' (fun (const a1')))] |
|
|
ps _isone = mkVSystem . Map.fromList $ [(del, omega), (psi, VLine (line (const (base VI1))) a1' a1' (fun (const a1')))] |
|
|
|
|
|
|
|
|
a1 = comp |
|
|
a1 = comp |
|
|
(fun (const (base VI1 @@ VItIsOne))) |
|
|
|
|
|
|
|
|
(fun (const (base VI1))) |
|
|
(phi VI1 `ior` psi) |
|
|
(phi VI1 `ior` psi) |
|
|
(system \j _u -> mkVSystem (Map.fromList [ (phi VI1, ielim (base VI1) a1' (vProj1 (equivs VI1 @@ VItIsOne)) alpha j) |
|
|
(system \j _u -> mkVSystem (Map.fromList [ (phi VI1, ielim (base VI1) a1' (vProj1 (equivs VI1 @@ VItIsOne)) alpha j) |
|
|
, (psi, a VI1)])) |
|
|
|
|
|
a1' |
|
|
|
|
|
|
|
|
, (psi, a VI1 VItIsOne)])) |
|
|
|
|
|
(VInc (base VI1) (phi VI1 `ior` psi) a1') |
|
|
b1 = glueElem (base VI1) (phi VI1) (types VI1) (equivs VI1) (fun (const t1)) a1 |
|
|
b1 = glueElem (base VI1) (phi VI1) (types VI1) (equivs VI1) (fun (const t1)) a1 |
|
|
in b1 |
|
|
in b1 |
|
|
|
|
|
|
|
|
VType -> VGlueTy a0 phi (fun \is1 -> u @@ VI1 @@ is1) |
|
|
|
|
|
(fun \i -> mapVSystem makeEquiv (u @@ inot i @@ VItIsOne)) |
|
|
|
|
|
|
|
|
VType -> VGlueTy a0 phi (fun' "is1" \is1 -> u @@ VI1 @@ is1) |
|
|
|
|
|
(fun' "is1" \_ -> mapVSystem makeEquiv (u @@ VVar (Bound (T.pack "_equivLine_") (negate 3)) @@ VItIsOne)) |
|
|
|
|
|
|
|
|
|
|
|
VNe (HData False _) Seq.Empty -> a0 |
|
|
VNe (HData False _) args -> |
|
|
VNe (HData False _) args -> |
|
|
case force a0 of |
|
|
case force a0 of |
|
|
VNe (HCon con_type con_name) con_args -> |
|
|
VNe (HCon con_type con_name) con_args -> |
|
@ -301,6 +306,9 @@ comp a psi@phi u incA0@(compOutS (a @@ VI1) phi (u @@ VI1 @@ VItIsOne) -> a0) = |
|
|
|
|
|
|
|
|
VNe (HData True _) args -> compHIT (length args) (a @@) phi u incA0 |
|
|
VNe (HData True _) args -> compHIT (length args) (a @@) phi u incA0 |
|
|
|
|
|
|
|
|
|
|
|
VLam{} -> error $ "comp VLam " ++ show (prettyTm (quote a)) |
|
|
|
|
|
sys@VSystem{} -> error $ "comp VSystem: " ++ show (prettyTm (quote sys)) |
|
|
|
|
|
|
|
|
_ -> VComp a phi u (VInc (a @@ VI0) phi a0) |
|
|
_ -> VComp a phi u (VInc (a @@ VI0) phi a0) |
|
|
|
|
|
|
|
|
mapVSystem :: (Value -> Value) -> Value -> Value |
|
|
mapVSystem :: (Value -> Value) -> Value -> Value |
|
@ -349,16 +357,16 @@ compConArgs total_args fam = go total_args where |
|
|
|
|
|
|
|
|
smuggle x = VNe (HData False (Bound "__comp_con_tyarg" (negate 10))) (Seq.singleton (PApp P.Ex x)) |
|
|
smuggle x = VNe (HData False (Bound "__comp_con_tyarg" (negate 10))) (Seq.singleton (PApp P.Ex x)) |
|
|
|
|
|
|
|
|
compOutS :: NFSort -> NFEndp -> Value -> Value -> Value |
|
|
|
|
|
|
|
|
compOutS :: HasCallStack => NFSort -> NFEndp -> Value -> Value -> Value |
|
|
compOutS a b c d = compOutS a b c (force d) where |
|
|
compOutS a b c d = compOutS a b c (force d) where |
|
|
compOutS _ _hi _0 vl@VComp{} = vl |
|
|
|
|
|
|
|
|
compOutS _ _hi _0 vl@VComp{} = vl |
|
|
compOutS _ _hi _0 (VInc _ _ x) = x |
|
|
compOutS _ _hi _0 (VInc _ _ x) = x |
|
|
compOutS a phi a0 v = outS a phi a0 v |
|
|
compOutS a phi a0 v = outS a phi a0 v |
|
|
|
|
|
|
|
|
system :: (Value -> Value -> Value) -> Value |
|
|
system :: (Value -> Value -> Value) -> Value |
|
|
system k = VLam P.Ex $ Closure (Bound "i" 0) \i -> VLam P.Ex $ Closure (Bound "phi" 0) \isone -> k i isone |
|
|
system k = VLam P.Ex $ Closure (Bound "i" 0) \i -> VLam P.Ex $ Closure (Bound "phi" 0) \isone -> k i isone |
|
|
|
|
|
|
|
|
fill :: NFLine -> NFEndp -> Value -> Value -> NFEndp -> Value |
|
|
|
|
|
|
|
|
fill :: HasCallStack => NFLine -> NFEndp -> Value -> Value -> NFEndp -> Value |
|
|
fill a phi u a0 j = |
|
|
fill a phi u a0 j = |
|
|
comp (line \i -> a @@ (i `iand` j)) |
|
|
comp (line \i -> a @@ (i `iand` j)) |
|
|
(phi `ior` inot j) |
|
|
(phi `ior` inot j) |
|
@ -377,7 +385,7 @@ glueElem :: NFSort -> NFEndp -> NFPartial -> NFPartial -> NFPartial -> Value -> |
|
|
glueElem _a (force -> VI1) _tys _eqvs t _vl = t @@ VItIsOne |
|
|
glueElem _a (force -> VI1) _tys _eqvs t _vl = t @@ VItIsOne |
|
|
glueElem a phi tys eqvs t vl = VGlue a phi tys eqvs t vl |
|
|
glueElem a phi tys eqvs t vl = VGlue a phi tys eqvs t vl |
|
|
|
|
|
|
|
|
unglue :: NFSort -> NFEndp -> NFPartial -> NFPartial -> Value -> Value |
|
|
|
|
|
|
|
|
unglue :: HasCallStack => NFSort -> NFEndp -> NFPartial -> NFPartial -> Value -> Value |
|
|
unglue _a (force -> VI1) _tys eqvs x = vProj1 (eqvs @@ VItIsOne) @@ x |
|
|
unglue _a (force -> VI1) _tys eqvs x = vProj1 (eqvs @@ VItIsOne) @@ x |
|
|
unglue _a _phi _tys _eqvs (force -> VGlue _ _ _ _ _ vl) = vl |
|
|
unglue _a _phi _tys _eqvs (force -> VGlue _ _ _ _ _ vl) = vl |
|
|
unglue a phi tys eqvs (force -> VSystem fs) = VSystem (fmap (unglue a phi tys eqvs) fs) |
|
|
unglue a phi tys eqvs (force -> VSystem fs) = VSystem (fmap (unglue a phi tys eqvs) fs) |
|
@ -434,21 +442,22 @@ contr a aC phi u = |
|
|
comp (line (const a)) |
|
|
comp (line (const a)) |
|
|
phi |
|
|
phi |
|
|
(system \i is1 -> ielim (line (const a)) (vProj1 aC) (u is1) (vProj2 aC @@ u is1) i) |
|
|
(system \i is1 -> ielim (line (const a)) (vProj1 aC) (u is1) (vProj2 aC @@ u is1) i) |
|
|
(vProj1 aC) |
|
|
|
|
|
|
|
|
(VInc a phi (vProj1 aC)) |
|
|
|
|
|
|
|
|
transp :: (NFEndp -> Value) -> Value -> Value |
|
|
transp :: (NFEndp -> Value) -> Value -> Value |
|
|
transp line a0 = comp (fun line) VI0 (system \_ _ -> VSystem mempty) (VInc (line VI0) VI0 a0) |
|
|
transp line a0 = comp (fun line) VI0 (system \_ _ -> VSystem mempty) (VInc (line VI0) VI0 a0) |
|
|
|
|
|
|
|
|
makeEquiv :: Value -> Value |
|
|
makeEquiv :: Value -> Value |
|
|
makeEquiv line = VPair f $ fun \y -> VPair (fib y) (fun \u -> p (vProj1 u) (vProj2 u) y) |
|
|
|
|
|
|
|
|
makeEquiv argh = VPair f $ fun \y -> VPair (fib y) (fun \u -> p (vProj1 u) (vProj2 u) y) |
|
|
where |
|
|
where |
|
|
|
|
|
line = fun \i -> substitute (Map.singleton (Bound (T.pack "_equivLine_") (negate 3)) (inot i)) argh |
|
|
a = line @@ VI0 |
|
|
a = line @@ VI0 |
|
|
b = line @@ VI1 |
|
|
b = line @@ VI1 |
|
|
|
|
|
|
|
|
f = fun \x -> transp (line @@) x |
|
|
f = fun \x -> transp (line @@) x |
|
|
g = fun \x -> transp ((line @@) . inot) x |
|
|
g = fun \x -> transp ((line @@) . inot) x |
|
|
u i = fun \x -> fill line VI0 (system \_ _ -> mkVSystem mempty) x i |
|
|
|
|
|
v i = fun \x -> fill (fun ((line @@) . inot)) VI0 (system \_ _ -> mkVSystem mempty) x i |
|
|
|
|
|
|
|
|
u i = fun \x -> fill line VI0 (system \_ _ -> mkVSystem mempty) (VInc a VI0 x) i |
|
|
|
|
|
v i = fun \x -> fill (fun ((line @@) . inot)) VI0 (system \_ _ -> mkVSystem mempty) (VInc a VI1 x) (inot i) |
|
|
|
|
|
|
|
|
fib y = VPair (g @@ y) (VLine b y (f @@ (g @@ y)) (fun (theta0 y VI1))) |
|
|
fib y = VPair (g @@ y) (VLine b y (f @@ (g @@ y)) (fun (theta0 y VI1))) |
|
|
theta0 y i j = fill line (ior j (inot j)) (system \i _ -> mkVSystem (Map.fromList [(j, v i @@ y), (inot j, u i @@ (g @@ y))])) (VInc a (ior j (inot j)) (g @@ y)) i |
|
|
theta0 y i j = fill line (ior j (inot j)) (system \i _ -> mkVSystem (Map.fromList [(j, v i @@ y), (inot j, u i @@ (g @@ y))])) (VInc a (ior j (inot j)) (g @@ y)) i |
|
|