The show-prettyprint package

[ Tags: bsd3, library, text, user-interfaces ] [ Propose Tags ]


[Skip to Readme]


Versions,,, 0.1.2,, 0.2
Change log
Dependencies ansi-wl-pprint, base (>=4.7 && <5), prettyprinter (<1.2), trifecta (>=1.6) [details]
License BSD3
Copyright David Luposchainsky, 2016
Author David Luposchainsky <dluposchainsky (λ) google>
Maintainer David Luposchainsky <dluposchainsky (λ) google>
Category User Interfaces, Text
Home page
Source repository head: git clone
Uploaded Thu Jun 1 15:19:02 UTC 2017 by quchen
Updated Thu Jun 8 21:14:20 UTC 2017 by quchen to revision 1
Distributions LTSHaskell:0.2, NixOS:0.2, Stackage:0.2, Tumbleweed:
Downloads 312 total (9 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-06-01 [all 1 reports]
Hackage Matrix CI




Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees

Readme for show-prettyprint-0.2

[back to package description]

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 ()))
          ,Right (Record {r1 = ('c'
                         ,r2 = 123}))]

Related packages

There is a similar package on Hackage called pretty-show, which takes a more flexible approach to prettyprinting show-formatted strings. This has its advantages and disadvantages.

  | prettyprint-show (this) | pretty-show (alternative) ------------- | ---------------------------------- | ----------------------------- Use case | fire and forget, debugging | flexible, working with the output API | One core value (rest: convenience) | Multiple combinable values Extensibility | low, not intended | decent, e.g. HTML rendering Robustness | high: only cares about parentheses, bugs in bad output can be hacked around | medium: relies on output that follows Haskell's lexical structure