diff options
Diffstat (limited to 'utils/CC/Pretty.hs')
-rw-r--r-- | utils/CC/Pretty.hs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/utils/CC/Pretty.hs b/utils/CC/Pretty.hs index 0a41abe..ccb886a 100644 --- a/utils/CC/Pretty.hs +++ b/utils/CC/Pretty.hs @@ -2,8 +2,32 @@ module CC.Pretty where class Pretty a where + {-# MINIMAL pretty | prettyPrec #-} pretty :: a -> String + pretty = prettyPrec (-1) + -- | Higher precedence binds tighter. + -- Parentheses are required if the printed element has lower precedence + -- than the Int argument. + prettyPrec :: Int -> a -> String + prettyPrec _ = pretty instance Pretty Int where pretty = show + + +-- Useful if you want the Pretty instance to be equal to the Show instance. +newtype PrettyShow a = PrettyShow a + deriving (Show) + +instance Show a => Pretty (PrettyShow a) where + pretty (PrettyShow x) = show x + + +pprint :: Pretty a => a -> IO () +pprint = putStrLn . pretty + +precParens :: Int -> Int -> String -> String +precParens environ self s + | self < environ = "(" ++ s ++ ")" + | otherwise = s |