module Tip.Pretty where
import Text.PrettyPrint
import Tip.Types
infixl 1 $\
class Pretty a where
pp :: a -> Doc
ppRender :: Pretty a => a -> String
ppRender = render . pp
pprint :: Pretty a => a -> IO ()
pprint = putStrLn . ppRender
instance PrettyVar String where
varStr = id
instance PrettyVar Int where
varStr = show
class PrettyVar a where
varStr :: a -> String
ppVar :: PrettyVar a => a -> Doc
ppVar = text . varStr
($\) :: Doc -> Doc -> Doc
d1 $\ d2 = hang d1 2 d2
parIf :: Bool -> Doc -> Doc
parIf True = parens
parIf False = id