Display empty results and no results differently

This commit is contained in:
Joscha 2020-12-13 23:53:13 +00:00
parent d473c8443f
commit a647b9e26f
2 changed files with 14 additions and 8 deletions

View file

@ -12,7 +12,12 @@ import Propa.Prolog.Parse
import Propa.Prolog.Unify import Propa.Prolog.Unify
parseAndRun :: T.Text -> T.Text -> IO () parseAndRun :: T.Text -> T.Text -> IO ()
parseAndRun dbText statsText = T.putStrLn $ either id id $ do parseAndRun dbText statsText = T.putStrLn $ case results of
db <- parseDb "<input>" dbText Left e -> e
stats <- parseStats "<input>" statsText Right [] -> "No."
pure $ T.intercalate "\n" $ map displayResult $ run db stats Right rs -> T.intercalate "\n" rs
where
results = do
db <- parseDb "<input>" dbText
stats <- parseStats "<input>" statsText
pure $ map displayResult $ run db stats

View file

@ -61,8 +61,9 @@ displayDefs :: [Def T.Text] -> T.Text
displayDefs = T.intercalate "\n" . map displayDef displayDefs = T.intercalate "\n" . map displayDef
displayResult :: Map.Map T.Text (Term T.Text) -> T.Text displayResult :: Map.Map T.Text (Term T.Text) -> T.Text
displayResult displayResult m | Map.null m = "Yes."
displayResult m
= T.intercalate "\n" = T.intercalate "\n"
. map (\(k, v) -> k <> " = " <> displayTerm v) $ map (\(k, v) -> k <> " = " <> displayTerm v)
. filter (\(k, v) -> v /= TVar k) $ filter (\(k, v) -> v /= TVar k)
. Map.assocs $ Map.assocs m