Display empty results and no results differently
This commit is contained in:
parent
d473c8443f
commit
a647b9e26f
2 changed files with 14 additions and 8 deletions
|
|
@ -12,7 +12,12 @@ import Propa.Prolog.Parse
|
|||
import Propa.Prolog.Unify
|
||||
|
||||
parseAndRun :: T.Text -> T.Text -> IO ()
|
||||
parseAndRun dbText statsText = T.putStrLn $ either id id $ do
|
||||
db <- parseDb "<input>" dbText
|
||||
stats <- parseStats "<input>" statsText
|
||||
pure $ T.intercalate "\n" $ map displayResult $ run db stats
|
||||
parseAndRun dbText statsText = T.putStrLn $ case results of
|
||||
Left e -> e
|
||||
Right [] -> "No."
|
||||
Right rs -> T.intercalate "\n" rs
|
||||
where
|
||||
results = do
|
||||
db <- parseDb "<input>" dbText
|
||||
stats <- parseStats "<input>" statsText
|
||||
pure $ map displayResult $ run db stats
|
||||
|
|
|
|||
|
|
@ -61,8 +61,9 @@ displayDefs :: [Def T.Text] -> T.Text
|
|||
displayDefs = T.intercalate "\n" . map displayDef
|
||||
|
||||
displayResult :: Map.Map T.Text (Term T.Text) -> T.Text
|
||||
displayResult
|
||||
displayResult m | Map.null m = "Yes."
|
||||
displayResult m
|
||||
= T.intercalate "\n"
|
||||
. map (\(k, v) -> k <> " = " <> displayTerm v)
|
||||
. filter (\(k, v) -> v /= TVar k)
|
||||
. Map.assocs
|
||||
$ map (\(k, v) -> k <> " = " <> displayTerm v)
|
||||
$ filter (\(k, v) -> v /= TVar k)
|
||||
$ Map.assocs m
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue