[commit: packages/pretty] large_docs, master, moretests: Add 'maybe*' variants to all bracketing functions (4badfbd)
git at git.haskell.org
git at git.haskell.org
Fri Jan 23 22:49:21 UTC 2015
Repository : ssh://git@git.haskell.org/pretty
On branches: large_docs,master,moretests
Link : http://git.haskell.org/packages/pretty.git/commitdiff/4badfbd6bfbc31098df2c6f19fe5b11f39c70174
>---------------------------------------------------------------
commit 4badfbd6bfbc31098df2c6f19fe5b11f39c70174
Author: David Terei <code at davidterei.com>
Date: Wed Dec 24 15:30:58 2014 -0800
Add 'maybe*' variants to all bracketing functions
>---------------------------------------------------------------
4badfbd6bfbc31098df2c6f19fe5b11f39c70174
src/Text/PrettyPrint/HughesPJ.hs | 25 +++++++++++++++++++++++++
src/Text/PrettyPrint/HughesPJClass.hs | 4 ++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/Text/PrettyPrint/HughesPJ.hs b/src/Text/PrettyPrint/HughesPJ.hs
index 509720b..9ed67b2 100644
--- a/src/Text/PrettyPrint/HughesPJ.hs
+++ b/src/Text/PrettyPrint/HughesPJ.hs
@@ -41,6 +41,7 @@ module Text.PrettyPrint.HughesPJ (
-- ** Wrapping documents in delimiters
parens, brackets, braces, quotes, doubleQuotes,
+ maybeParens, maybeBrackets, maybeBraces, maybeQuotes, maybeDoubleQuotes,
-- ** Combining documents
empty,
@@ -385,6 +386,30 @@ parens p = char '(' <> p <> char ')'
brackets p = char '[' <> p <> char ']'
braces p = char '{' <> p <> char '}'
+-- | Apply 'parens' to 'Doc' if boolean is true.
+maybeParens :: Bool -> Doc -> Doc
+maybeParens False = id
+maybeParens True = parens
+
+-- | Apply 'brackets' to 'Doc' if boolean is true.
+maybeBrackets :: Bool -> Doc -> Doc
+maybeBrackets False = id
+maybeBrackets True = brackets
+
+-- | Apply 'braces' to 'Doc' if boolean is true.
+maybeBraces :: Bool -> Doc -> Doc
+maybeBraces False = id
+maybeBraces True = braces
+
+-- | Apply 'quotes' to 'Doc' if boolean is true.
+maybeQuotes :: Bool -> Doc -> Doc
+maybeQuotes False = id
+maybeQuotes True = quotes
+
+-- | Apply 'doubleQuotes' to 'Doc' if boolean is true.
+maybeDoubleQuotes :: Bool -> Doc -> Doc
+maybeDoubleQuotes False = id
+maybeDoubleQuotes True = doubleQuotes
-- ---------------------------------------------------------------------------
-- Structural operations on GDocs
diff --git a/src/Text/PrettyPrint/HughesPJClass.hs b/src/Text/PrettyPrint/HughesPJClass.hs
index da1b474..ebf6ea2 100644
--- a/src/Text/PrettyPrint/HughesPJClass.hs
+++ b/src/Text/PrettyPrint/HughesPJClass.hs
@@ -65,9 +65,9 @@ appPrec :: Rational
appPrec = 10
-- | Parenthesize an value if the boolean is true.
+{-# DEPRECATED prettyParen "Please use 'maybeParens' instead" #-}
prettyParen :: Bool -> Doc -> Doc
-maybeParens False = id
-maybeParens True = parens
+prettyParen = maybeParens
-- Various Pretty instances
instance Pretty Int where pPrint = int
More information about the ghc-commits
mailing list