show-prettyprint

Robust prettyprinter for output of auto-generated Show instances https://github.com/quchen/show-prettyprint#readme

Latest on Hackage:0.3.0.1@rev:1

See all snapshots show-prettyprint appears in

BSD-3-Clause licensed and maintained by David Luposchainsky <dluposchainsky (λ) google>

Module documentation for 0.1.2

This version can be pinned in stack with:show-prettyprint-0.1.2@sha256:77d24389b373da827d4aa7b6fa37d0919ea4cb95895830aada098874a94ce947,1585

Prettyprint Show output

Output of nested data structures by Show instances is often very hard to read. This package offers a simple function to insert line breaks and indentation into that output so that the semantics are unchanged, but makes it much easier to read.

The package does not rely on a parser for actual Haskell; instead, it merely reacts on parentheses, commas and the like. This makes it fairly robust even in the face of invalid Show instances, that may not produce valid Haskell code.

For example, consider this nested data structure:

nestedExample = fromList
    [ ("hello", Left  (Pair True ()))
    , ("world", Right (Record { r1 = ('c', -1.2e34), r2 = 123 }))
    , ("!"    , Left  (Pair False ())) ]

Applying show to it results in the fairly dense representation

fromList [("!",Left (Pair False ())),("hello",Left (Pair True ())),("world",Right (Record {r1 = ('c',-1.2e34), r2 = 123}))]

With the functions defined in this module, we can make this output a bit more readable,

fromList [("!"
          ,Left (Pair False ()))
         ,("hello",Left (Pair True ()))
         ,("world"
          ,Right (Record {r1 = ('c'
                               ,-1.2e34)
                         ,r2 = 123}))]