module PP
where
import Text.PrettyPrint.HughesPJ as PP
import Text.PrettyPrint.HughesPJ(Doc,text,char,int,(<>),(<+>),($+$),($$),render)

class PP a where
  pp :: a -> Doc

instance PP Bool where
  pp True = text "True"
  pp False = text "False"

instance PP Int where
    pp = int

instance PP Char where
    pp = char
    
instance PP Integer where
    pp = integer

instance PP () where
    pp () = text "()"

instance PP a => PP (Maybe a) where
    pp (Just x) = PP.parens $ text "Just" <+> pp x
    pp Nothing = text "Nothing"


instance (PP a, PP b) => PP (Either a b) where
    pp (Left x) = PP.parens $ text "Left" <+> pp x
    pp (Right x) = PP.parens $ text "Right" <+> pp x

instance PP a => PP [a] where
    pp = set

set :: (PP a) => [a] -> Doc
set s = PP.braces $ PP.sep $ PP.punctuate PP.comma (map pp s)

langle = text "<"
rangle = text ">"
angles d = langle <> d <> rangle 

instance (PP a, PP b) => PP (a,b) where
    pp (x,y) = angles $ pp x <> comma <+> pp y

instance (PP a, PP b, PP c) => PP (a,b,c) where
    pp (x,y,z) = angles $ pp x <> comma <+> pp y <> comma <+> pp z
