2020-05-08 01:18:26 +04:00
|
|
|
{-
|
|
|
|
Pretty printer, based on GHC one.
|
|
|
|
-}
|
2020-05-01 19:04:29 +04:00
|
|
|
|
|
|
|
module Pretty
|
|
|
|
( module Pretty
|
|
|
|
, module Text.PrettyPrint
|
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import Data.Text
|
|
|
|
|
|
|
|
import Text.PrettyPrint hiding ((<>))
|
|
|
|
|
2020-05-08 01:18:26 +04:00
|
|
|
-- | With this, one can `data X = ...; derive Show via PP X`
|
2020-05-01 19:04:29 +04:00
|
|
|
newtype PP a = PP { unPP :: a }
|
|
|
|
|
|
|
|
instance Pretty a => Show (PP a) where
|
|
|
|
show = show . pp . unPP
|
|
|
|
|
2020-05-08 01:18:26 +04:00
|
|
|
-- | Pretty-printable types.
|
2020-05-01 19:04:29 +04:00
|
|
|
class Pretty p where
|
|
|
|
pp :: p -> Doc
|
|
|
|
|
2020-05-08 01:18:26 +04:00
|
|
|
-- | Common instance.
|
2020-05-01 19:04:29 +04:00
|
|
|
instance Pretty Text where
|
|
|
|
pp = text . unpack
|
|
|
|
|
2020-05-08 01:18:26 +04:00
|
|
|
-- | TODO: tuple, not list; actually /use/ it.
|
2020-05-01 19:04:29 +04:00
|
|
|
wrap [l, r] a = hang (hang l 2 r) 0 r
|