Operads-0.2: Math/Operad/PPrint.hs
-- Copyright 2009 Mikael Vejdemo Johansson <mik@stanford.edu>
-- Released under a BSD license
-- | Pretty printing for user interaction.
module Math.Operad.PPrint where
import Data.List (intercalate)
-- * Pretty printing
-- | This yields user interface functions for human readable printing of objects.
-- The idea is to use 'Show' instances for marshalling of data, and 'PPrint' for
-- user interaction.
class PPrint a where
pp :: a -> String
pP :: a -> IO ()
pP = putStrLn . pp
instance (PPrint a) => PPrint [a] where
pp rs = "[" ++ (intercalate ",\n" (map pp rs)) ++ "]"
instance (PPrint a, PPrint b) => PPrint (a,b) where
pp (r,t) = "(" ++ pp r ++ "," ++ pp t ++ ")"