instance Show Env where
show = render . showEnv True
showEnv :: Bool -> Env -> Doc
showEnv b e =
let
names x = if b then text x <+> equals else PP.empty
par x = if b then parens x else x
com = if b then comma else PP.empty
showEnv1 e = case e of
Env (Upd x env,u:us,fs,os) ->
showEnv1 (Env (env,us,fs,os)) <+> names x <+> showVal1 u <> com
Env (Sub i env,us,phi:fs,os) ->
showEnv1 (Env (env,us,fs,os)) <+> names (show i) <+> text (show phi) <> com
Env (Def _ _ env,vs,fs,os) -> showEnv1 (Env (env,vs,fs,os))
_ -> showEnv b e
in case e of
Env (Empty,_,_,_) -> PP.empty
Env (Def _ _ env,vs,fs,os) -> showEnv b (Env (env,vs,fs,os))
Env (Upd x env,u:us,fs,os) ->
par $ showEnv1 (Env (env,us,fs,os)) <+> names x <+> showVal1 u
Env (Sub i env,us,phi:fs,os) ->
par $ showEnv1 (Env (env,us,fs,os)) <+> names (show i) <+> text (show phi)
instance Show Loc where
show = render . showLoc
showLoc :: Loc -> Doc
showLoc (Loc name (i,j)) = text (show (i,j) ++ " in " ++ name)
showFormula :: C.Formula -> Doc
showFormula phi = case phi of
_ C.:\/: _ -> parens (text (show phi))
_ C.:/\: _ -> parens (text (show phi))
_ -> text $ show phi
instance Show Ter where
show = render . showTer
showTer :: Ter -> Doc
showTer v = case v of
U -> char 'U'
App e0 e1 -> showTer e0 <+> showTer1 e1
Pi e0 -> text "Pi" <+> showTer e0
Lam x t e -> char '\\' <> parens (text x <+> colon <+> showTer t) <+>
text "->" <+> showTer e
Fst e -> showTer1 e <> text ".1"
Snd e -> showTer1 e <> text ".2"
Sigma e0 -> text "Sigma" <+> showTer1 e0
Pair e0 e1 -> parens (showTer e0 <> comma <> showTer e1)
Where e d -> showTer e <+> text "where" <+> showDecls d
Var x -> text x
Con c es -> text c <+> showTers es
PCon c a es phis -> text c <+> braces (showTer a) <+> showTers es
<+> hsep (map ((char '@' <+>) . showFormula) phis)
Split f _ _ _ -> text f
Sum _ n _ -> text n
HSum _ n _ -> text n
Undef{} -> text "undefined"
Hole{} -> text "?"
PathP e0 e1 e2 -> text "PathP" <+> showTers [e0,e1,e2]
PLam i e -> char '<' <> text (show i) <> char '>' <+> showTer e
AppFormula e phi -> showTer1 e <+> char '@' <+> showFormula phi
Comp e t ts -> text "comp" <+> showTers [e,t] <+> text (C.showSystem ts)
HComp e t ts -> text "hComp" <+> showTers [e,t] <+> text (C.showSystem ts)
Fill e t ts -> text "fill" <+> showTers [e,t] <+> text (C.showSystem ts)
Glue a ts -> text "Glue" <+> showTer1 a <+> text (C.showSystem ts)
GlueElem a ts -> text "glue" <+> showTer1 a <+> text (C.showSystem ts)
UnGlueElem a ts -> text "unglue" <+> showTer1 a <+> text (C.showSystem ts)
Id a u v -> text "Id" <+> showTers [a,u,v]
IdPair b ts -> text "idC" <+> showTer1 b <+> text (C.showSystem ts)
IdJ a t c d x p -> text "idJ" <+> showTers [a,t,c,d,x,p]
showTers :: [Ter] -> Doc
showTers = hsep . map showTer1
showTer1 :: Ter -> Doc
showTer1 t = case t of
U -> char 'U'
Con c [] -> text c
Var{} -> showTer t
Undef{} -> showTer t
Hole{} -> showTer t
Split{} -> showTer t
Sum{} -> showTer t
HSum{} -> showTer t
Fst{} -> showTer t
Snd{} -> showTer t
_ -> parens (showTer t)
showDecls :: Decls -> Doc
showDecls (MutualDecls _ defs) =
hsep $ punctuate comma
[ text x <+> equals <+> showTer d | (x,(_,d)) <- defs ]
showDecls (OpaqueDecl i) = text "opaque" <+> text i
showDecls (TransparentDecl i) = text "transparent" <+> text i
showDecls TransparentAllDecl = text "transparent_all"
instance Show Val where
show = render . showVal
showVal :: Val -> Doc
showVal v = case v of
VU -> char 'U'
Ter t@Sum{} rho -> showTer t <+> showEnv False rho
Ter t@HSum{} rho -> showTer t <+> showEnv False rho
Ter t@Split{} rho -> showTer t <+> showEnv False rho
Ter t rho -> showTer1 t <+> showEnv True rho
VCon c us -> text c <+> showVals us
VPCon c a us phis -> text c <+> braces (showVal a) <+> showVals us
<+> hsep (map ((char '@' <+>) . showFormula) phis)
VHComp v0 v1 vs -> text "hComp" <+> showVals [v0,v1] <+> text (C.showSystem vs)
VPi a l@(VLam x t b)
| "_" `isPrefixOf` x -> showVal1 a <+> text "->" <+> showVal1 b
| otherwise -> char '(' <> showLam v
VPi a b -> text "Pi" <+> showVals [a,b]
VPair u v -> parens (showVal u <> comma <> showVal v)
VSigma u v -> text "Sigma" <+> showVals [u,v]
VApp u v -> showVal u <+> showVal1 v
VLam{} -> text "\\(" <> showLam v
VPLam{} -> char '<' <> showPLam v
VSplit u v -> showVal u <+> showVal1 v
VVar x _ -> text x
VOpaque x _ -> text ('#':x)
VFst u -> showVal1 u <> text ".1"
VSnd u -> showVal1 u <> text ".2"
VPathP v0 v1 v2 -> text "PathP" <+> showVals [v0,v1,v2]
VAppFormula v phi -> showVal v <+> char '@' <+> showFormula phi
VComp v0 v1 vs ->
text "comp" <+> showVals [v0,v1] <+> text (C.showSystem vs)
VGlue a ts -> text "Glue" <+> showVal1 a <+> text (C.showSystem ts)
VGlueElem a ts -> text "glue" <+> showVal1 a <+> text (C.showSystem ts)
VUnGlueElem a ts -> text "unglue" <+> showVal1 a <+> text (C.showSystem ts)
VUnGlueElemU v b es -> text "unglue U" <+> showVals [v,b]
<+> text (C.showSystem es)
VCompU a ts -> text "comp (<_> U)" <+> showVal1 a <+> text (C.showSystem ts)
VId a u v -> text "Id" <+> showVals [a,u,v]
VIdPair b ts -> text "idC" <+> showVal1 b <+> text (C.showSystem ts)
VIdJ a t c d x p -> text "idJ" <+> showVals [a,t,c,d,x,p]
showPLam :: Val -> Doc
showPLam e = case e of
VPLam i a@VPLam{} -> text (show i) <+> showPLam a
VPLam i a -> text (show i) <> char '>' <+> showVal a
_ -> showVal e