Skip to content

Commit

Permalink
More output structure indentation. #71
Browse files Browse the repository at this point in the history
  • Loading branch information
epost committed Aug 9, 2019
1 parent 7f1f5e4 commit 981b555
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Language/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ showCtx' :: (Show a1, Show a2) => Map a1 a2 -> String
showCtx' m = intercalate "\n\t" $ (\(k,v) -> show k ++ " : " ++ show v) <$> Map.toList m

section :: String -> String -> String
section heading body = heading ++ "\n" ++ indentLines body ++ "\n"
section heading body = heading ++ "\n" ++ indentLines body

indentLines :: String -> String
indentLines = foldMap (\l -> "\t" <> l <> "\n"). lines
Expand Down
24 changes: 13 additions & 11 deletions src/Language/Instance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,18 @@ instance (Show InstanceEx) where
instance (TyMap Show '[var, ty, sym, en, fk, att, gen, sk, x, y], Eq en, Eq fk, Eq att)
=> Show (Instance var ty sym en fk att gen sk x y) where
show (Instance _ p _ alg) =
"instance\n" ++
(indentLines $ "presentation" ++ "\n" ++ show p) ++ "\n" ++
(indentLines $ "algebra" ++ "\n" ++ show alg) ++ "\n"
section "instance" $ unlines
[ section "presentation" (show p)
, section "algebra" (show alg)
]

instance TyMap Show '[var, ty, sym, en, fk, att, gen, sk]
=> Show (Presentation var ty sym en fk att gen sk) where
show (Presentation ens' _ eqs') =
unlines
[ section "generators" $ showCtx' ens'
, section "equations" $ intercalate "\n" $ Set.map show eqs'
]

instance (TyMap Show '[var, ty, sym, en, fk, att, gen, sk, x, y], Eq en, Eq fk, Eq att)
=> Show (Algebra var ty sym en fk att gen sk x y) where
Expand Down Expand Up @@ -870,11 +879,4 @@ prettyEntityTable alg@(Algebra sch en' _ _ _ _ _ _ _) es =
-- prettyAtt :: x -> (att, w) -> String
prettyAtt x (att,_) = prettyTerm $ aAtt alg att x

prettyTerm = show

instance TyMap Show '[var, ty, sym, en, fk, att, gen, sk]
=> Show (Presentation var ty sym en fk att gen sk) where
show (Presentation ens' _ eqs') =
indentLines $
"generators\n\t" ++ showCtx' ens' ++ "\n" ++
"equations\n\t" ++ intercalate "\n\t" (Set.map show eqs') ++ "\n"
prettyTerm = show
20 changes: 11 additions & 9 deletions src/Language/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ instance TyMap Eq '[var, ty, sym, en, fk, att]

instance TyMap Show '[var, ty, sym, en, fk, att]
=> Show (Schema var ty sym en fk att) where
show (Schema _ ens' fks' atts' path_eqs' obs_eqs' _) = "schema {\n" ++
"entities\n\t" ++ intercalate "\n\t" (Prelude.map show $ Set.toList ens') ++
"\nforeign_keys\n\t" ++ intercalate "\n\t" fks'' ++
"\natts\n\t" ++ intercalate "\n\t" atts'' ++
"\npath_equations\n\t" ++ intercalate "\n\t" (eqs'' path_eqs') ++
"\nobservation_equations\n\t " ++ intercalate "\n\t" (eqs'' obs_eqs') ++ " }"
show (Schema _ ens' fks' atts' path_eqs' obs_eqs' _) =
section "schema" $ unlines
[ section "entities" $ unlines $ show <$> Set.toList ens'
, section "foreign_keys" $ unlines $ fks''
, section "atts" $ unlines $ atts''
, section "path_equations" $ unlines $ eqs'' path_eqs'
, section "observation_equations " $ unlines $ eqs'' obs_eqs'
]
where
fks'' = Prelude.map (\(k,(s,t)) -> show k ++ " : " ++ show s ++ " -> " ++ show t) $ Map.toList fks'
atts'' = Prelude.map (\(k,(s,t)) -> show k ++ " : " ++ show s ++ " -> " ++ show t) $ Map.toList atts'
eqs'' x = Prelude.map (\(en,EQ (l,r)) -> "forall x : " ++ show en ++ " . " ++ show (mapVar "x" l) ++ " = " ++ show (mapVar "x" r)) $ Set.toList x
fks'' = (\(k,(s,t)) -> show k ++ " : " ++ show s ++ " -> " ++ show t) <$> Map.toList fks'
atts'' = (\(k,(s,t)) -> show k ++ " : " ++ show s ++ " -> " ++ show t) <$> Map.toList atts'
eqs'' x = (\(en,EQ (l,r)) -> "forall x : " ++ show en ++ " . " ++ show (mapVar "x" l) ++ " = " ++ show (mapVar "x" r)) <$> Set.toList x

-- | Checks that the underlying theory is well-sorted.
-- I.e. rule out "1" = one kind of errors.
Expand Down
15 changes: 9 additions & 6 deletions src/Language/Typeside.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ instance (Eq var, Eq ty, Eq sym) => Eq (Typeside var ty sym) where
= (tys' == tys'') && (syms' == syms'') && (eqs' == eqs'')

instance (Show var, Show ty, Show sym) => Show (Typeside var ty sym) where
show (Typeside tys' syms' eqs' _) = "typeside {\n" ++
"types\n\t" ++ intercalate "\n\t" (Prelude.map show $ Set.toList tys') ++
"\nfunctions\n\t" ++ intercalate "\n\t" syms'' ++
"\nequations\n\t" ++ intercalate "\n\t" eqs'' ++ " }"
where syms'' = Prelude.map (\(k,(s,t)) -> show k ++ " : " ++ show s ++ " -> " ++ show t) $ Map.toList syms'
eqs'' = Prelude.map (\(k,s) -> "forall " ++ showCtx k ++ " . " ++ show s) $ Set.toList eqs'
show (Typeside tys' syms' eqs' _) =
section "typeside" $ unlines
[ section "types" $ unlines . fmap show $ Set.toList tys'
, section "functions" $ unlines syms''
, section "equations" $ unlines eqs''
]
where
syms'' = (\(k,(s,t)) -> show k ++ " : " ++ show s ++ " -> " ++ show t) <$> Map.toList syms'
eqs'' = (\(k,s) -> "forall " ++ showCtx k ++ " . " ++ show s) <$> Set.toList eqs'

instance (NFData var, NFData ty, NFData sym) => NFData (Typeside var ty sym) where
rnf (Typeside tys0 syms0 eqs0 eq0) = deepseq tys0 $ deepseq syms0 $ deepseq eqs0 $ deepseq eq0 ()
Expand Down

0 comments on commit 981b555

Please sign in to comment.