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