pretty-simple-0.2.0.0: Simple pretty printer for any datatype with a 'Show' instance.

Copyright(c) Dennis Gosnell 2016
LicenseBSD-style (see LICENSE file)
Maintainercdep.illabout@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Text.Pretty.Simple

Contents

Description

 

Synopsis

Documentation

pShow :: Show a => a -> String Source #

pPrint :: (MonadIO m, Show a) => a -> m () Source #

Examples

Simple Haskell datatype:

>>> data Foo a = Foo a String deriving Show
>>> pPrint $ Foo 3 "hello"
Foo 3 "hello"

Lists:

>>> pPrint $ [1,2,3]
[ 1
, 2
, 3
]

Slightly more complicated lists:

>>> pPrint $ [ Foo [ (),    () ] "hello" ]
[ Foo
    [ ()
    , ()
    ] "hello"
]
>>> pPrint $ [ Foo [ "bar", "baz" ] "hello", Foo [] "bye" ]
[ Foo
    [ "bar"
    , "baz"
    ] "hello"
, Foo [] "bye"
]

Record:

>>> :{
data Bar b = Bar
  { barInt :: Int
  , barA :: b
  , barList :: [Foo Double]
  } deriving Show
:}
>>> pPrint $ Bar 1 [10, 11] [Foo 1.1 "", Foo 2.2 "hello"]
Bar
    { barInt = 1
    , barA =
        [ 10
        , 11
        ]
    , barList =
        [ Foo 1.1 ""
        , Foo 2.2 "hello"
        ]
    }

Newtype:

>>> newtype Baz = Baz { unBaz :: [String] } deriving Show
>>> pPrint $ Baz ["hello", "bye"]
Baz
    { unBaz =
        [ "hello"
        , "bye"
        ]
    }