From 354ede1ea60a5bab3fcfd4d792c49c8161375f1a Mon Sep 17 00:00:00 2001 From: Paul Chiusano Date: Mon, 10 May 2021 20:43:03 -0500 Subject: [PATCH] Elide unit from `display` output --- .../src/Unison/CommandLine/DisplayValues.hs | 19 ++++++++++++++++--- parser-typechecker/src/Unison/TermPrinter.hs | 6 ++++-- .../transcripts-using-base/doc.output.md | 2 -- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/parser-typechecker/src/Unison/CommandLine/DisplayValues.hs b/parser-typechecker/src/Unison/CommandLine/DisplayValues.hs index fc16d90f7..5e6cf59b5 100644 --- a/parser-typechecker/src/Unison/CommandLine/DisplayValues.hs +++ b/parser-typechecker/src/Unison/CommandLine/DisplayValues.hs @@ -41,7 +41,20 @@ displayTerm :: (Var v, Monad m) -> (Reference -> m (Maybe (DD.Decl v ()))) -> Term v () -> m Pretty -displayTerm pped terms typeOf eval types = \case +displayTerm = displayTerm' False + +type ElideUnit = Bool + +displayTerm' :: (Var v, Monad m) + => ElideUnit -- whether to elide printing of `()` from the end of the block + -> PPE.PrettyPrintEnvDecl + -> (Reference -> m (Maybe (Term v ()))) + -> (Referent -> m (Maybe (Type v ()))) + -> (Term v () -> m (Maybe (Term v ()))) + -> (Reference -> m (Maybe (DD.Decl v ()))) + -> Term v () + -> m Pretty +displayTerm' elideUnit pped terms typeOf eval types = \case tm@(Term.Apps' (Term.Constructor' typ _) _) | typ == DD.docRef -> displayDoc pped terms typeOf eval types tm | typ == DD.doc2Ref -> do @@ -65,7 +78,7 @@ displayTerm pped terms typeOf eval types = \case P.wrap $ "Sadly, I don't know the error, but you can evaluate" <> "the above expression in a scratch file to see it." ] - src tm = TP.prettyBlock (PPE.suffixifiedPPE pped) tm + src tm = TP.prettyBlock elideUnit (PPE.suffixifiedPPE pped) tm -- assume this is given a -- Pretty.Annotated ann (Either SpecialForm ConsoleText) @@ -144,7 +157,7 @@ displayPretty pped terms typeOf eval types tm = go tm DD.Doc2SpecialFormExampleBlock n (DD.Doc2Example vs body) -> -- todo: maybe do something with `vs` to indicate the variables are free - P.indentN 4 <$> displayTerm pped terms typeOf eval types ex + P.indentN 4 <$> displayTerm' True pped terms typeOf eval types ex where ex = Term.lam' (ABT.annotation body) (drop (fromIntegral n) vs) body -- Link (Either Link.Type Doc2.Term) diff --git a/parser-typechecker/src/Unison/TermPrinter.hs b/parser-typechecker/src/Unison/TermPrinter.hs index b93c3eab3..ab72ce783 100644 --- a/parser-typechecker/src/Unison/TermPrinter.hs +++ b/parser-typechecker/src/Unison/TermPrinter.hs @@ -50,8 +50,10 @@ import qualified Unison.ConstructorType as CT pretty :: Var v => PrettyPrintEnv -> Term v a -> Pretty ColorText pretty env = PP.syntaxToColor . pretty0 env emptyAc . printAnnotate env -prettyBlock :: Var v => PrettyPrintEnv -> Term v a -> Pretty ColorText -prettyBlock env = PP.syntaxToColor . pretty0 env emptyBlockAc . printAnnotate env +prettyBlock :: Var v => Bool -> PrettyPrintEnv -> Term v a -> Pretty ColorText +prettyBlock elideUnit env = + PP.syntaxToColor . pretty0 env (emptyBlockAc { elideUnit = elideUnit }) + . printAnnotate env pretty' :: Var v => Maybe Width -> PrettyPrintEnv -> Term v a -> ColorText pretty' (Just width) n t = diff --git a/unison-src/transcripts-using-base/doc.output.md b/unison-src/transcripts-using-base/doc.output.md index 6f977f756..0b20df466 100644 --- a/unison-src/transcripts-using-base/doc.output.md +++ b/unison-src/transcripts-using-base/doc.output.md @@ -287,7 +287,6 @@ and the rendered output using `display`: cube x = use Nat * x * x * x - () .> view includingSource @@ -625,7 +624,6 @@ Lastly, it's common to build longer documents including subdocuments via `{{ sub cube x = use Nat * x * x * x - () # Including Unison source code